Click to See Complete Forum and Search --> : What am I doing wrong
delbert Harry
April 20th, 1999, 12:40 PM
int CSQLEngine::Set_New_Line(CString s_Line)
{
int String_Line_Index = 0;
int stringLen;
char *tmpChar;
do
{
stringLen = strlen(strchr(s_Line , ','));
strncpy(tmpChar, s_Line + stringLen, 2);//
Word_List_Start = Word_List_Start + stringLen + 1;
//String routines
}while( (int)strlen(s_Line) > (int)String_Line_Index );
return(0);
}
the compiler won't let me use the integer in the strchr function. I would like to use it like an offset to start searching from.
April 20th, 1999, 01:33 PM
I would make the following suggestion:
CString tmpChar;
do
{
stringLen = s_Line.Find(",", String_Line_Index);
tmpChar = s_Line.Mid(String_Line_Index, stringLen);
String_Line_Index+=stringLen;
// I believe what I read is you are trying to break out strings between comma's
// I may have the math a little off but this will basicly do that.
// The rest of your string stuff
...
} While()
Paul McKenzie
April 20th, 1999, 01:49 PM
s_Line is defined as a CString. You are adding an integer to a class called CString, not a character array. The '+' operator is overloaded in CString as a concatenation operator. You think that you have a character array, but you don't.
Either change your function to use *all* CStrings and use the CString functions to manipulate the string, or change the prototype of the function to this:
int CSQLEngine::Set_New_Line(char *s_Line)
OR
int CSQLEngine::Set_New_Line(const char *s_Line)
if s_Line doesn't change and/or you want to pass a CString that won't be changed by Set_New_Line function.
Mixing old style string.h functions with string classes seems to be one of the things that many new coders to C++ seem to be doing, and it just leads to more confusion.
Regards,
Paul McKenzie
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.