473,408 Members | 1,759 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,408 software developers and data experts.

Compile error C2664 - Why??

When I compile it, I get a "error C2664: 'ExtractID' : cannot convert
parameter 1 from 'char' to 'char []'" error and I don't understand why.
I am just learning C++, so keep it simple. One more note, I have the
program compiled using strings instead of char[]; however, I should be
able to convert all my strings to char[] and get the program to
compile. Right? Here is my code. Thanks.

// Written by David Hoffman
// Sept 30, 2003

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

//Function Prototypes
bool TestValidLine(char[]);
void ExtractID(char[], char[]);

int main()
{
char cRawLine[70];
char cidNumber[8];
bool bLastGood = true;
char wait;

ifstream RawList;
ofstream NewList;
RawList.open("RAWLIST.txt");
NewList.open("NEWLIST.txt");

//Loop while not EOF and the last line read was valid.
while (RawList.getline(cRawLine, 80) && bLastGood)
{
bLastGood = TestValidLine(cRawLine);
if (bLastGood)
{
//Extract data from line.
ExtractID(cRawLine[70], cidNumber[8]);
cin >> wait;
}
}
//Close files here.
RawList.close();
NewList.close();

return 0;
}

bool TestValidLine(char cRawLine[])
{
return ((cRawLine[0] == '|') && (cRawLine[strlen(cRawLine)] == '|'));
}

void ExtractID(char cRawLine[], char cidNumber[])
{
int x;
for (x = 0; x <= 6; x++)
{
cidNumber[x] = cRawLine[x + 6];
}
cout << cidNumber << "\n";
}
Jul 19 '05 #1
4 25625
David Hoffman wrote:
When I compile it, I get a "error C2664: 'ExtractID' : cannot convert
parameter 1 from 'char' to 'char []'" error and I don't understand
why.
You should always mark the line that produced the error, though it's
quite obvious in this case.
I am just learning C++, so keep it simple. One more note, I have
the program compiled using strings instead of char[]; however, I
should be able to convert all my strings to char[] and get the program
to compile. Right?
Yes.
Here is my code. Thanks.

// Written by David Hoffman
// Sept 30, 2003

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

//Function Prototypes
bool TestValidLine(char[]);
void ExtractID(char[], char[]);

int main()
{
char cRawLine[70];
char cidNumber[8];
bool bLastGood = true;
char wait;

ifstream RawList;
ofstream NewList;
RawList.open("RAWLIST.txt");
NewList.open("NEWLIST.txt");

//Loop while not EOF and the last line read was valid.
while (RawList.getline(cRawLine, 80) && bLastGood)
Why do you specify a size of 80 to getline? Your array can only take 70
characters.
{
bLastGood = TestValidLine(cRawLine);
if (bLastGood)
{
//Extract data from line.
ExtractID(cRawLine[70], cidNumber[8]);
This call is wrong. cRawLine[70] is not the array itself, but rather the
71st character of it (which is btw one beyond the bounds of the array).
Similar for cidNumber. The compiler cannot convert a char into a
pointer to it, that's why it's complaining. Just try:

ExtractID(cRawLine, cidNumber);
cin >> wait;
}
}
//Close files here.
RawList.close();
NewList.close();
Closing the files here isn't neccesary, since it's done automatically
when the streams are destroyed. It doesn't hurt though.

return 0;
}

bool TestValidLine(char cRawLine[])
{
return ((cRawLine[0] == '|') && (cRawLine[strlen(cRawLine)] ==
'|'));
That test won't work. cRawLine[strlen(cRawLine)] is always a '\0'
character. If cRawLine is e.g. "Test":

strlen(cRawLine) == 4
cRawLine[0] == 'T'
cRawLine[1] == 'e'
cRawLine[2] == 's'
cRawLine[3] == 't'
cRawLine[4] == '\0' == cRawLine[strlen(cRawLine)]
}

void ExtractID(char cRawLine[], char cidNumber[])
{
int x;
for (x = 0; x <= 6; x++)
{
cidNumber[x] = cRawLine[x + 6];
}
cout << cidNumber << "\n";
}


Jul 19 '05 #2

"David Hoffman" <da**********@cableone.net>
??????:f0*************************@posting.google. com...
When I compile it, I get a "error C2664: 'ExtractID' : cannot convert
parameter 1 from 'char' to 'char []'" error and I don't understand why.
I am just learning C++, so keep it simple. One more note, I have the
program compiled using strings instead of char[]; however, I should be
able to convert all my strings to char[] and get the program to
compile. Right? Here is my code. Thanks.

// Written by David Hoffman
// Sept 30, 2003

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

//Function Prototypes
bool TestValidLine(char[]);
void ExtractID(char[], char[]);

int main()
{
char cRawLine[70];
char cidNumber[8];
bool bLastGood = true;
char wait;

ifstream RawList;
ofstream NewList;
RawList.open("RAWLIST.txt");
NewList.open("NEWLIST.txt");

//Loop while not EOF and the last line read was valid.
while (RawList.getline(cRawLine, 80) && bLastGood)
{
bLastGood = TestValidLine(cRawLine);
if (bLastGood)
{
//Extract data from line.
ExtractID(cRawLine[70], cidNumber[8]);
cin >> wait;
}
}
//Close files here.
RawList.close();
NewList.close();

return 0;
}

bool TestValidLine(char cRawLine[])
{
return ((cRawLine[0] == '|') && (cRawLine[strlen(cRawLine)] == '|')); }

void ExtractID(char cRawLine[], char cidNumber[])
{
int x;
for (x = 0; x <= 6; x++)
{
cidNumber[x] = cRawLine[x + 6];
}
cout << cidNumber << "\n";
}

ExtractID(cRawLine[70], cidNumber[8]); // !! error is here

change it as follow : ExtractID(cRawLine, cidNumber);
The reason is : cRawLine[70] and cidNumber[8] are char, it is a element ,
not a array!

Jul 19 '05 #3
David Hoffman wrote:
When I compile it, I get a "error C2664: 'ExtractID' : cannot convert
parameter 1 from 'char' to 'char []'" error and I don't understand why.
I am just learning C++, so keep it simple. One more note, I have the
program compiled using strings instead of char[]; however, I should be
able to convert all my strings to char[] and get the program to
compile. Right? Here is my code. Thanks.

// Written by David Hoffman
// Sept 30, 2003

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

//Function Prototypes
bool TestValidLine(char[]);
void ExtractID(char[], char[]);

int main()
{
char cRawLine[70]; Beware, this must be cRawLine[80] char cidNumber[8];
bool bLastGood = true;
char wait;

ifstream RawList;
ofstream NewList;
RawList.open("RAWLIST.txt");
NewList.open("NEWLIST.txt");

//Loop while not EOF and the last line read was valid.
while (RawList.getline(cRawLine, 80) && bLastGood)
{
bLastGood = TestValidLine(cRawLine);
if (bLastGood)
{
//Extract data from line.
ExtractID(cRawLine[70], cidNumber[8]);


Trivial, cRawLine[70] is a char, and ExtractID expects a char* (or
char[]). If you change ExtractId(char[]... to ExtractId(char*,... and
change this line to: ExtractId(&cRawLine[70],.... all will work as you
expect.
Jul 19 '05 #4
Juan Antonio Domínguez Pérez <do*****@dominpe.com> wrote in message news:<bm**********@news.ya.com>...
David Hoffman wrote:
When I compile it, I get a "error C2664: 'ExtractID' : cannot convert
parameter 1 from 'char' to 'char []'" error and I don't understand why.
I am just learning C++, so keep it simple. One more note, I have the
program compiled using strings instead of char[]; however, I should be
able to convert all my strings to char[] and get the program to
compile. Right? Here is my code. Thanks.

// Written by David Hoffman
// Sept 30, 2003

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

//Function Prototypes
bool TestValidLine(char[]);
void ExtractID(char[], char[]);

int main()
{
char cRawLine[70]; Beware, this must be cRawLine[80]
char cidNumber[8];
bool bLastGood = true;
char wait;

ifstream RawList;
ofstream NewList;
RawList.open("RAWLIST.txt");
NewList.open("NEWLIST.txt");

//Loop while not EOF and the last line read was valid.
while (RawList.getline(cRawLine, 80) && bLastGood)
{
bLastGood = TestValidLine(cRawLine);
if (bLastGood)
{
//Extract data from line.
ExtractID(cRawLine[70], cidNumber[8]);


Thanks. Making the 2 changes you said did make the difference. The 80
was a typo, it was supposed to be 70. I was trying so many different
things to get the function ExtractID to work I forgot to change that
back to 70. Now I can't get the while loop to run. All this program
does now is quit when it gets to that line. I will try to find a
solution on the web. I also understand that what I forgot to do with
the function ExtractID was to setup pointers to the variables in
memory. Thanks again.
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Scott Chang | last post by:
Hi all I copied the following VC++ 6.0 code (written by someone in the website) to my VC++ .Net 2002-Windows XP Pro PC ////****Solution 'dyndllclass' (2 projects)***/// ///***dynapp****(1st...
1
by: rr | last post by:
trying to compile bounce.c from msvcc's help on multi-thread. i get the error: c:\Applications\C++ Step By Step\begthrd\begthrd.cpp(82): error C2664: '_beginthread' : cannot convert parameter...
0
by: rr | last post by:
trying to compile bounce.c from msvcc's help on multi-thread. i get the error: c:\Applications\C++ Step By Step\begthrd\begthrd.cpp(82): error C2664: '_beginthread' : cannot convert parameter...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
10
by: B Williams | last post by:
I have been working with this code for a better part of the day and I can't figure out where I am making a mistake. I can only imagine it is when I declare multiple paramaters on the constructor...
1
TMS
by: TMS | last post by:
I'm trying to write an address book that is based on a binary tree. I'm devloping in Visual C++ (I blew up my Ubuntu with the new dist, so no EMACS), starting with the basics: #ifndef...
2
by: Nick | last post by:
I'm learning C++ and ran into a compile error using Visual C++ 2005 Express on the following example program (located at http://www.cplusplus.com/doc/tutorial/templates.html): // template...
0
by: FrankCheung | last post by:
I am using VS 2005 c++ ReportViewer to generate a dynamic report with a date filter. The following is the code contained in the form.h: public: void SetReportParameters() { ...
3
by: Angus | last post by:
Hi I have a class CRequest with a function: bool IsFinished() const; I have a list of these CRequests - list<CRequestmylist. I create a function object to find if a CRequest is finished:...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
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...

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.