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(c har[]);
void ExtractID(char[], char[]);
int main()
{
char cRawLine[70];
char cidNumber[8];
bool bLastGood = true;
char wait;
ifstream RawList;
ofstream NewList;
RawList.open("R AWLIST.txt");
NewList.open("N EWLIST.txt");
//Loop while not EOF and the last line read was valid.
while (RawList.getlin e(cRawLine, 80) && bLastGood)
{
bLastGood = TestValidLine(c RawLine);
if (bLastGood)
{
//Extract data from line.
ExtractID(cRawL ine[70], cidNumber[8]);
cin >> wait;
}
}
//Close files here.
RawList.close() ;
NewList.close() ;
return 0;
}
bool TestValidLine(c har 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";
} 4 25644
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(c har[]); void ExtractID(char[], char[]);
int main() { char cRawLine[70]; char cidNumber[8]; bool bLastGood = true; char wait;
ifstream RawList; ofstream NewList; RawList.open("R AWLIST.txt"); NewList.open("N EWLIST.txt");
//Loop while not EOF and the last line read was valid. while (RawList.getlin e(cRawLine, 80) && bLastGood)
Why do you specify a size of 80 to getline? Your array can only take 70
characters.
{ bLastGood = TestValidLine(c RawLine); if (bLastGood) { //Extract data from line. ExtractID(cRawL ine[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(cRawL ine, 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(c har 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"; }
"David Hoffman" <da**********@c ableone.net>
??????:f0****** *************** ****@posting.go ogle.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(c har[]); void ExtractID(char[], char[]);
int main() { char cRawLine[70]; char cidNumber[8]; bool bLastGood = true; char wait;
ifstream RawList; ofstream NewList; RawList.open("R AWLIST.txt"); NewList.open("N EWLIST.txt");
//Loop while not EOF and the last line read was valid. while (RawList.getlin e(cRawLine, 80) && bLastGood) { bLastGood = TestValidLine(c RawLine); if (bLastGood) { //Extract data from line. ExtractID(cRawL ine[70], cidNumber[8]); cin >> wait; } } //Close files here. RawList.close() ; NewList.close() ;
return 0; }
bool TestValidLine(c har 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(cRawL ine[70], cidNumber[8]); // !! error is here
change it as follow : ExtractID(cRawL ine, cidNumber);
The reason is : cRawLine[70] and cidNumber[8] are char, it is a element ,
not a array!
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(c har[]); 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("R AWLIST.txt"); NewList.open("N EWLIST.txt");
//Loop while not EOF and the last line read was valid. while (RawList.getlin e(cRawLine, 80) && bLastGood) { bLastGood = TestValidLine(c RawLine); if (bLastGood) { //Extract data from line. ExtractID(cRawL ine[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(&cRaw Line[70],.... all will work as you
expect.
Juan Antonio Domínguez Pérez <do*****@dominp e.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(c har[]); 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("R AWLIST.txt"); NewList.open("N EWLIST.txt");
//Loop while not EOF and the last line read was valid. while (RawList.getlin e(cRawLine, 80) && bLastGood) { bLastGood = TestValidLine(c RawLine); if (bLastGood) { //Extract data from line. ExtractID(cRawL ine[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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 project)***//
//----dynapp.cpp----/
#include <windows.h
#include "dynclass.h
int main ( void
|
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 1 from 'void (char *)' to 'void
(__cdecl *)(void *)'
any help?
|
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 1 from 'void (char *)' to 'void
(__cdecl *)(void *)'
any help?
|
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 it.
here is the 4 errors.
c:\C++\Ch15\Employee.h(29): error C2440: '=' : cannot convert from
'char ' to 'char '
|
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 because the program compiles
with just one parameter. Can someone look at this and tell me where I made
my error?
This is the error I get while trying to compile.
error C2664: 'GradeBook::GradeBook(const GradeBook &)' : cannot convert...
| |
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 binarySearchTree_h
#define binarySearchTree_h
#include <string>
#include <iostream>
using namespace std;
|
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 specialization
#include <iostream>
using namespace std;
template <class T>
class container {
|
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()
{
ReportParameter^ DatePara = gcnew ReportParameter("ShowDate",this->datepick->Value.ToString());
this->reportViewer1->LocalReport->SetParameters( gcnew array<ReportParameter^>{DatePara});
|
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:
class is_finished : public std::unary_function<CRequest, bool>
{
|
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:
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |