CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2002
    Location
    Riverdale, NYC, NY, USA
    Posts
    5

    Question a huge pointer-string problem

    Hello,
    I have a big problem with pointers and strings -- it seems that I cannot compare string with another string. In the code snippet below, i am trying to compare normal. with whatever value is in the word variable at the moment. If there is a "normal." then the script ouputs 0, if not, then an 1.

    The problem is that where the script should output 0, it outputs 1. And where there it should output 1, it outputs 1 (no problem here).

    The code deals with the input of many lines, each line having 42 fields separated from each other by comma. The code finds the 42nd field which contains either normal. value or any other word with dot at the end.

    What should I do? Please help ASAP: please answer on the same day this message was posted.



    Code:
            for(a=0; !infile.eof();){
    // read in one line
                    char *p;
                    char word[20] = "";
                    infile.getline(buff,200);
                    p = strtok(buff,",");
                    for(int i=0; i<42; i++)
                    {
                            if(i==41)
                            {
                                    strcpy(word,p);
    
                                    if (word=="normal.")
                                    {
                                            cout<<"0";
                                            outfile<<"0";
                                    }
                                    else
                                    {
                                          cout<<"1";
                                          outfile<<"1";
                                    }
                            }
    
                            p = strtok(NULL,",");
                    }
                    cout<<endl;
                    outfile << endl;
                    a++;
            }
    __________________
    Dmitry Kashlev
    Dmitry Kashlev

  2. #2
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    use strcmp instead of (word == "normal")

  3. #3
    Join Date
    Aug 2002
    Location
    Riverdale, NYC, NY, USA
    Posts
    5

    Thumbs up thanks!

    thanks alot!
    Dmitry Kashlev

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