i've writtn a c++ code, and i like to count the output,i mean

1 ---
2
3 

like that, the code is good just the counter, everytime when i run the program i got this kind of error

ISO C++ forbids comparison between pointer and integer

i really don't know why, so any idea why and how could i avoid this kind of error.
this is the code, it's not all the code but everthing doing well except the counter. PLEASE ANY IDEA:

 iofile::iofile()
 {
 }

  FILE *outfile;
  char *programname;
  int iofile::CreateAllNodes(Link **Dhead, Link **Ahead)
     {

         FILE *MyFile;
         long iEndFile, iFSize; 
         char WordBuffer[24];
         char NameBuffer[40];

         cout<< " what file would you like to sort"<<endl;
         cin >> NameBuffer;
         getchar();

       MyFile = fopen( NameBuffer, "r");                                             //check for file, open input file for read
    if (MyFile == NULL)

       {
       cout<<"\ncould not open the file\n";
       cout<<" I have failed you...  I'm sorry.\n\n";
       }

   else if((outfile = fopen("outfile.csv", "w+"))==NULL)                        //check for file, open output file for write 
       {
        printf("File opened successfully.\n");

        exit(1);
        }




         fseek(MyFile, 0L, SEEK_END);                                           //size get file size
         iEndFile = ftell(MyFile);                                              // the end of the file is the size of the file
         iFSize = iEndFile;
         rewind(MyFile);

    while (ftell(MyFile) < iEndFile)                                            //read file
       {

         fscanf(MyFile," %s", WordBuffer);                                       //read data from file


        if (WordBuffer[0] == 'ä' || WordBuffer[0] == 'Z')                       //load nodes && Compare characters to load in proper node using an if-else statement
           {
               _linkedlist.AddToList(Dhead, WordBuffer);
           }
        else
           {
               _linkedlist.AddToList(Ahead, WordBuffer);                                    // add words to the list
           }        
        }

              fclose(MyFile);                                                        //close the input file

     }

 void iofile::WalkNode(Link *headNode)
    {
         Link *currentNode = headNode;
         int lines = 0;
         string getSpatie(string item);
         int i;


        cout<<" word       timesappear"<<endl;   


      while (currentNode != NULL)
        {               
             [COLOR="Red"]for(i=1; i<currentNode; i++)[/COLOR]
             {
            cout<<i<< getSpatie(currentNode->word)<< currentNode- >numTimesAppear<<endl;
            fprintf(outfile," %-24s %5d\n",currentNode->word, currentNode->numTimesAppear);
            lines++;

          if (lines %20 == 19)
            {
            cout<<"Press enter for more data"<<endl;
            getchar();
            }
            currentNode = (Link *)currentNode->next;
          }

            cout<<"End of list. Press Enter"<<endl;                                      //testing to make sure I am out of the loop
            getchar();
            fclose(outfile);

         }
}


string getSpatie(string item){
       string _item = item;
       string spatie, s = " ";

       int lengte = item.length(), i, einde = 27;
       einde -= lengte;
       for(i = 0; i < einde; i++){
             spatie+= s;
             }
             _item += spatie;
             return _item;
             }

  void iofile::error(const int erroecode, char *const message, char *const argument)
    {
           cout<<stderr<<endl;
           cout<<stderr<< message<< argument;
           exit(EXIT_FAILURE);
     }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

1> 16 posts and yet no code tag

2> U are comparing integer with a node pointer in the following line:

for(i=1; i<currentNode; i++)/*i : integer, currentNode : a pointer..............................ERROR IN HERE*/
{
       cout<<i<< getSpatie(currentNode->word)<< currentNode->numTimesAppear<<endl;
        /*remaining codes*/

I think u are looking for something like

for(i=1; i<currentNode->numTimesAppear; i++)
{
        cout<<i<< getSpatie(currentNode->word)<< currentNode->numTimesAppear<<endl;
        /*remaining codes*/

Edited 7 Years Ago by dkalita: n/a

well thanx for reaction,
but when i run the program i got nothing cause (currentNode->numTimesAppear) count only howmany time the word used in the text. i need to count the words for example:
1 apple
2 room
3 class
like that :idea:

This article has been dead for over six months. Start a new discussion instead.