Random Homebrew: PSP SysMon by xmOD
This system monitor application

text file search and write...

Programming on your favorite platform, for your favorite platform? Post here

text file search and write...

Postby varun » Mon Jan 16, 2012 3:43 pm

Advertising
i was making a program that reads a text file(2of12.txt) word by word, searches it in second one(all_dict.txt)..if not found it pastes it into second one....the problem is that it only pastes 1st letter of each word plz help.

Code: Select all
void main()
{   ifstream myReadFile,x2;
   ofstream myWriteFile;
   char output[100],s[100];
   myReadFile.open("2of12.txt");
   x2.open("all_dict.txt");
   
   int i,flag;
   for( i = 0; i<100; i++, output[i] = '\0',s[i]= '\0');
   
   if (myReadFile.is_open() && x2.is_open())
   {   
      while(!myReadFile.eof())
      {   
         flag = 0;
         myReadFile >> output;
         while(!x2.eof())
         {   for( i = 0; i<100; i++, output[i] = '\0',s[i]= '\0');
            x2>>s;
            if(strcmp(s,output)==0) flag = 1;
         }
         x2.seekg(0,ios::beg); //reset read pos to beginning
         x2.clear(); //clear eofbit
         
         if(flag==0)
         {
            
            myWriteFile.open ("all_dict.txt",ios_base::app);
            myWriteFile<<output<<endl;
            myWriteFile.close();
            myWriteFile.clear(); //clear eofbit
         
         }
            
      }
   }

   myReadFile.seekg(0,std::ios::beg); //reset read pos to beginning
   myReadFile.clear(); //clear eofbit
   myReadFile.close();

   


}


also after some time i get this error
Code: Select all
Run-Time Check Failure #2 - Stack around the variable 's' was corrupted.


plz help
Attachments
text.rar
(120.63 KiB) Downloaded 12 times
User avatar
varun
Banned
 
Posts: 1059
Joined: Thu Jan 27, 2011 12:32 pm
Location: Mars

Re: text file search and write...

Postby psPea » Sat Feb 04, 2012 9:48 pm

Advertising
Code: Select all
         while(!x2.eof())
         {   for( i = 0; i<100; i++, output[i] = '\0',s[i]= '\0');
            x2>>s;
            if(strcmp(s,output)==0) flag = 1;
         }

Your for loop is erasing all but the first character in output
I'm assuming you're using it to clear the buffers, which is not achieved
you should use memset or some c++ equivalent instead.
User avatar
psPea
 
Posts: 43
Joined: Sat May 21, 2011 7:04 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

Friends

Coding 'n Cracking - Nymphaea - PS3 Forum - darkforestgroup - daxhordes.org - Tgames - coldbird - gopsp.it - pspstation.org - prometheus - hgoel.info - MakeSmartTV - ps vita