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.c pp(69) : error C2664: 'GetDriveTypeA' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cas t, C-style cast or function-style cast
...\EraseTest.c pp(71) : error C2664: 'PathExists' : cannot convert parameter 1 from 'bool' to 'char []'
Conversion from integral type to pointer type requires reinterpret_cas t, C-style cast or function-style cast
Error executing cl.exe.
8 2610
the && is just in there because I dont know what to put there...
thanks
Banfa 9,065
Recognized Expert Moderator Expert
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.c pp(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
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.
sicarie 4,677
Recognized Expert Moderator Specialist
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.
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}
}
for this line...
char* p_IQ;
I also tried string* p_IQ which doest work either
Banfa 9,065
Recognized Expert Moderator Expert
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.
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";
}}}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 must be many know the answer here.
thanks
|
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
myprog2.cpp: In method `Line::Line (Point, Point)':
myprog2.cpp:32: no matching function for call to `Point::Point ()'
|
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 numbers two decimal
places long like 10.01 I only know how to define numbers as int or double.
Do I use float?
Also, I'm using Visual Studio .NET is there anyway to keep the compiler on
the screen long enough to actually see what it's outputting. ...
|
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 -- comments welcome!
"Create beginner's programs"
<url: http://home.no.net/dubjai/win32cpptut/w32cpptut_01_07.zip>
This part focuses on basic techniques and approaches to programming,
so it could have been titled "Basic methodologies and...
|
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 msg that im
getting: "Error executing cl.exe"
this is the code that I have, but I know whats causing it, ill just
show you the whole thing first though
//file: Quadratic
| |
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 experimenting a bit with what I need to do this and have the following code snippet. But first if I pass the assembly name and
type to Activator.CreateInstance() it always fails. However if I walk my assembly and get a type value, the call to...
|
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!
|
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 of
free IDE. So I discovered that I needed to download a virtual server,
so I downloaded OmniSecure and followed the set up instructions as far
as I could figure them out.
So here is where I'm stuck.
1) While trying to set up and configure...
|
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
|
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 programmer and looking for a starting point in
regards to practical projects to work on.
What are some projects that beginner programmers usually start with?
Please list a few that would be good for a beginner PHP programmer to
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |