CString questions
-
I have been reading in a file using the getline function and using a (,) as a delimiter. I made a string caled name.
string name;
Then I do agetline(fin, name, ',');
I need to put the names in a char array. I thought I was doing that until I needed to use the names and I was getting garbage instead of the names I thought I was putting in the char array. I was doing this to add them to the array which gives me junk.Names[i] = stdup(name.c_str())
How can I read in a list of names 3 - 8 characters long and store them in a char arrray? I can't have an array of strings because of other constraints. Thanks, Steven -
I have been reading in a file using the getline function and using a (,) as a delimiter. I made a string caled name.
string name;
Then I do agetline(fin, name, ',');
I need to put the names in a char array. I thought I was doing that until I needed to use the names and I was getting garbage instead of the names I thought I was putting in the char array. I was doing this to add them to the array which gives me junk.Names[i] = stdup(name.c_str())
How can I read in a list of names 3 - 8 characters long and store them in a char arrray? I can't have an array of strings because of other constraints. Thanks, StevenWhere's the
CString
problem here? :) ;) Best regards, Alexandru Savescu P.S. Interested in art? Visit this! -
I have been reading in a file using the getline function and using a (,) as a delimiter. I made a string caled name.
string name;
Then I do agetline(fin, name, ',');
I need to put the names in a char array. I thought I was doing that until I needed to use the names and I was getting garbage instead of the names I thought I was putting in the char array. I was doing this to add them to the array which gives me junk.Names[i] = stdup(name.c_str())
How can I read in a list of names 3 - 8 characters long and store them in a char arrray? I can't have an array of strings because of other constraints. Thanks, StevenIf you can be sure that you have enough space in your
Names[i]
field, then dostrcpy(Names[i], name.c_str());
instead of
Names[i] = strdup(name.c_str());
I seem to remember that your Names definition was an array of
char
s, in which case this would work. Hope this helps,Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
If you can be sure that you have enough space in your
Names[i]
field, then dostrcpy(Names[i], name.c_str());
instead of
Names[i] = strdup(name.c_str());
I seem to remember that your Names definition was an array of
char
s, in which case this would work. Hope this helps,Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
Ryan Binns wrote: I seem to remember that your Names definition was an array of chars, in which case this would work. Hmmm, I think it was an array of 45 char pointers, which made little sense since (!) the numeric members of that structure were NOT arrays. Edit: Looks like we were both right. In one post he had
struct TSimHeader
{
char Name[45];
...
}and in another he had
struct TSimHeader
{
char *Name[45];
...
} -
If you can be sure that you have enough space in your
Names[i]
field, then dostrcpy(Names[i], name.c_str());
instead of
Names[i] = strdup(name.c_str());
I seem to remember that your Names definition was an array of
char
s, in which case this would work. Hope this helps,Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
Ryan, When I use the strcpy() function I get the error: D:\.......cpp(105) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast The array that I am trying to put the ;name in is a char[]. Any Ideas? Stevne
-
Ryan, When I use the strcpy() function I get the error: D:\.......cpp(105) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast The array that I am trying to put the ;name in is a char[]. Any Ideas? Stevne
Post the definition of
Names
. That will help :)Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Ryan Binns wrote: I seem to remember that your Names definition was an array of chars, in which case this would work. Hmmm, I think it was an array of 45 char pointers, which made little sense since (!) the numeric members of that structure were NOT arrays. Edit: Looks like we were both right. In one post he had
struct TSimHeader
{
char Name[45];
...
}and in another he had
struct TSimHeader
{
char *Name[45];
...
}You have a good memoy, But if you rememeber, I have to actually put the chars in the array and not just the pointers because the array is getting sent to another PC. The recieving PC would have no use for the pointers on my machine. here is my structure.
**struct TSimSignal { int SimWriteFlag; int DisplayReadFlag; double Value[45]; double TimeStamp; }static TSimSignal_arr[1]; struct TSimHeader { char Name[45]; char Unit[45]; double Min[45]; double Max[45]; int SignalCount; int SimStatus; }static TSimHeader_arr[1];**
Once again back to putting junk in the char arrays (Name and Unit) thanks, steven -
Post the definition of
Names
. That will help :)Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
I posted them in a reply above this one. Thanks Ryan, Steven
-
You have a good memoy, But if you rememeber, I have to actually put the chars in the array and not just the pointers because the array is getting sent to another PC. The recieving PC would have no use for the pointers on my machine. here is my structure.
**struct TSimSignal { int SimWriteFlag; int DisplayReadFlag; double Value[45]; double TimeStamp; }static TSimSignal_arr[1]; struct TSimHeader { char Name[45]; char Unit[45]; double Min[45]; double Max[45]; int SignalCount; int SimStatus; }static TSimHeader_arr[1];**
Once again back to putting junk in the char arrays (Name and Unit) thanks, stevenTSimHeader header;
strcpy(header.Name, name.c_str());Should do the trick. If you're sending an array of
TSimHeader
's then you'll have something like this:TSimHeader headers[10];
strcpy(header[0].Name, name.c_str());Similarly for other members of the array. Hope this helps,
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"