CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    92

    What am I doing wrong

    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.


  2. #2
    Guest

    Re: What am I doing wrong

    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()


  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: What am I doing wrong

    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



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured