473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Beginner help needed

6
I am new to c++ (Visual C++ 6.0) and I am having some trouble getting this code to work properly. I come from a very different style of coding which is nothing like c or c++. Please help me get this code working properly. This is not for a project or program I am just trying to ensure I know what I am doing before I actually write a usefull program (long ways away I know)

Here is the code that I would like to execute:

#include <windows.h>
#include <stdio.h>
#include <iostream.h>
#include <String>

using namespace std;

int test();
bool PathExists(char pathtocheck[50]);


int test()
{
char i;
for (i='A'; i='Z'; i++)
{
if(GetDriveType(i) == DRIVE_FIXED)
{
if (PathExists(i && ":\\FOLDER PATH") == 1)
{
//do something if true
//not concerned about this code
}
}
}
return 0;
}

And here are the error messages


Compiling...
EraseTest.cpp
...\EraseTest.cpp(69) : error C2664: 'GetDriveTypeA' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
...\EraseTest.cpp(71) : error C2664: 'PathExists' : cannot convert parameter 1 from 'bool' to 'char []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Mar 27 '07 #1
8 2592
hammb
6
the && is just in there because I dont know what to put there...

thanks
Mar 27 '07 #2
Banfa
9,065 Expert Mod 8TB
for (i='A'; i='Z'; i++)

You need to look up the difference between assignment = and conditional equal to ==. This for loop assigns the value 'A' to i, then it assigns the value 'Z' to i since 'Z' != 0 it executes the loop then it increments i then it assigns the value 'Z' to i again. It would run forever.



if(GetDriveType(i) == DRIVE_FIXED)

EraseTest.cpp
...\EraseTest.cpp(69) : error C2664: 'GetDriveTypeA' : cannot convert parameter 1 from 'char' to 'const char *'

GetDriveType takes a parameter of type const char * (typedef'd to LPCSTR) however you have tried to pass it a parameter of type char. It is expecting a string which is an array of printable characters followed by a terminating 0 character. 'A' is a character constant but "A" is a string where the first and only character is an 'A'. However "A" is 2 characters long because it has a terminating 0 (NULL) character.

GetDriveType is expecting a string.

Note the error is on GetDriveTypeA because GetDriveType is a #defined symbol that is defined to point either at the narrow (single byte) character function GetDriveTypeA or the wide (multi-byte) character function GetDriveTypeW. This is a common feature in Windows.



if (PathExists(i && ":\\FOLDER PATH") == 1)

The reason you do not know what you put in place of the && is because there is nothing you can put in place there to concatenate a char (i) and a string literal.

To concatenate 2 strings you would have to use a function like strcat or a class like string
Mar 28 '07 #3
hammb
6
for (i='A'; i='Z'; i++)

* changed to:

for (i = 'A'; i <= 'Z'; i++)

* if(GetDriveType(i) == DRIVE_FIXED)

can you tell me how to get the value from i above into this function properly


if (PathExists(i && ":\\FOLDER PATH") == 1)

The reason you do not know what you put in place of the && is because there is nothing you can put in place there to concatenate a char (i) and a string literal.

To concatenate 2 strings you would have to use a function like strcat or a class like string

*Please provide an example.
*Here is what I tried:

char strcpy;
strcpy (str, c);
* and it doesn't work.
Mar 28 '07 #4
sicarie
4,677 Expert Mod 4TB
for (i='A'; i='Z'; i++)

* changed to:

for (i = 'A'; i <= 'Z'; i++)

* if(GetDriveType(i) == DRIVE_FIXED)

can you tell me how to get the value from i above into this function properly


if (PathExists(i && ":\\FOLDER PATH") == 1)

The reason you do not know what you put in place of the && is because there is nothing you can put in place there to concatenate a char (i) and a string literal.

To concatenate 2 strings you would have to use a function like strcat or a class like string

*Please provide an example.
*Here is what I tried:

char strcpy;
strcpy (str, c);
* and it doesn't work.
If you read Banfa's post again, you will see he suggested strcat, not strcpy (which copies one into the other, it does not combine them, which is what strcat does). Reread his post and links, and try again. You have the right idea (I think), just keep at it.
Mar 28 '07 #5
hammb
6
Almost there...

Thanks a million.. I have already learned so much from this post.
Here is what I have now.. The last thing I need help with is assigning the string pointer value.
--------------------------------------------------------------------------------------------------------
char i;
string iS;
string iT;
string IQ;
char* p_IQ;

for (i='A'; i<='Z'; i++)
{
iS = ":\\";
iT = i;
IQ = iT + iS;

//p_IQ = &IQ; //This doesnt work
//strcpy(p_IQ, IQ); //This doesnt work either

if(GetDriveType(p_IQ) == DRIVE_FIXED)
{//DO SOMETHING IF IT WORKS}
}
Mar 30 '07 #6
hammb
6
for this line...

char* p_IQ;

I also tried string* p_IQ which doest work either
Mar 30 '07 #7
Banfa
9,065 Expert Mod 8TB
there is a member methof of string, string::c_str() which returns a const char * pointer to the data in the string.

However you can not just copy this to p_IQ because you have not allocated any data to p_IQ (it is unitialised) so you would cause a memory exception.
Mar 30 '07 #8
hammb
6
so here it is.. Works perfectly. I want to thank you guys. I really appreciate the help.

{
char i;
string iS;
string iT;
string IQ;
char* p_IQ;

for (i='A'; i<='Z'; i++)
{
iS = ":\\";
iT = i;

IQ = iT + iS;

p_IQ = new char[IQ.length() + 1];
strcpy(p_IQ, IQ.c_str());

if(GetDriveType(p_IQ) == DRIVE_FIXED)
{
cout << IQ << "is a fixed drive\n";
}}}
Mar 31 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
15
by: PhilB | last post by:
Hello experts, I am a complete beginner in C++ (although I know C). I am trying to compile the code below, and I get the following error. Can anyone explain to me my mistake? Thanks! PhilB ...
7
by: BobJohnson | last post by:
Just started learning C++ and I need some help with my homework, shouldn't take long for people around here. I need to create a simple money calculator but I don't know how to make the output...
0
by: Alf P. Steinbach | last post by:
The seventh part of my attempted Correct C++ tutorial is now available, although for now only in Word format (use free Open Office if no Word), and also, it's not yet been reviewed at all -- ...
8
by: Bshealey786 | last post by:
Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
20
by: weight gain 2000 | last post by:
Hello all! I'm looking for a very good book for an absolute beginner on VB.net or VB 2005 with emphasis on databases. What would you reccommend? Thanks!
10
by: See_Red_Run | last post by:
Hi, I am trying to figure out how to get started with PHP/MySQL. Everything I've read so far says to start with PHP first. I was expecting something like Visual Basic Express or some other type...
9
by: Daniel | last post by:
Looking to see if anyone can offer some suggestions on some good VB.net books? looking for beginner to intermidiate and to expert.. Any suggestions? -- ASP, SQL2005, DW8 VBScript
22
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.