Help with ISO errors

This is a discussion on Help with ISO errors within the C++ Programming forums, part of the General Programming Boards category; Trying to get program to compile I keep recieving the following error:" ISO C++ forbids comparision between pointer and integer" ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    7

    Help with ISO errors

    Trying to get program to compile I keep recieving the following error:" ISO C++ forbids comparision between pointer and integer"

    Any help is appreciated
    Alpha22

    Code:
    int enterAmts (float Ca[])
    
    {
        int i = 0;
        int idx = 0;
        int count = 0;
        char cont;
        string namefile;
        string catName;
        float catAmts;
        float numcat = 0;
        
        infile.open(namefile.c_str());    
        infile >> catName[idx];  
       
       
       while(!infile.eof()){
           infile >> catName[idx];
           numcat ++;
           }   
           
        while(i < 10 && catName [idx]!= "zzz"){ //problem area
        
           cout << "Enter amt for " << catName[i] << "$" << flush;
           runResults << "Enter amt for " << catName[i] << "$" << endl;
           cin >> catAmts[i];
           runResults << catAmts[i] << endl;
           count += i;
           i++;
         }//endwhile
         infile.close();
        //  outfile.close();
      return 0;
    }//endmain

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Lose the space between the variable name and index. Also that index represents a single character and therefor will never equal "zzz"
    Sent from my iPadŽ

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Lose the space between the variable name and index.
    Why? That will only make it look better. There's nothing wrong with the space.

    Use the array without an index reference.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Code:
    string catName;
    If I then do this:
    Code:
    catName = "Sam";
    what is catName[0]? What type is it? How do you indicate a char literal? Then, can this be correct:
    Code:
    catName [idx] != "zzz"

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    7
    Should I change the inx to just i?

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    No. You want to change it to just plain "catName". catName[anything] is a character, and catName is a string. You're comparing in to a string, so you want catName, not catName[something].
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    7
    CatName is a string of names for budget category's.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    No, it isn't.
    Code:
    string catName;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Quote Originally Posted by dwks
    Why? That will only make it look better. There's nothing wrong with the space.

    Use the array without an index reference.
    Ick, I hate the way it looks. Personally, I think the index should appear as an extension of the variable, not a seperate thing. Anyway, the idea was really him not comparing against the single character, but I also think he was trying to compare against a substring, not the whole string.

    If you are looking for a specific substring and you know where it would start in the string, then you can use the substr() function.

    Code:
    catName.substr(6,3); // substr([Starting Index], [Size of substring])
    Last edited by SlyMaelstrom; 02-18-2006 at 04:12 PM.
    Sent from my iPadŽ

  10. #10
    Registered User
    Join Date
    Feb 2006
    Posts
    7
    Thanks dwks and 7stud damm thing will compile now. Another set of eyes always helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 05:20 PM
  3. Errors: ISO scoping, obsolete binding??
    By -JM in forum C++ Programming
    Replies: 3
    Last Post: 10-28-2005, 08:56 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21