| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with C style string
My program here is suppossed to read from a file a bunch of characters using c-style strings. The File contains a paragraph with 1 word per line. I got it to read it and store it into a multi dimentional array ok, but im also suppossed to not store duplicate words. I tried and i can't figure out why what im doing isn't working. If any one could please help me that would be Great! Thanks Heres my code. . .
#include <iostream> #include <fstream> using namespace std; int main() { fstream inputFile("input3.txt",ios::in);//open file if (!inputFile) { cerr<< "File could not be opened" << endl; exit(1); } char c,ary[90][12],checkary[12]; int col=0,row=0,x; for(row=0;row<90;row++) //Nulls out every element of array { for(col=0;col<12;col++) { ary[row][col] = '\0'; } } for(col=0;col<12;col++) //Nulls out every element of check array { checkary[col] = '\0'; } row = 0; col = 0; while(!inputFile.eof())//reads each character from file, then places it in array. { inputFile.get(c); if( c != '\0') { ary[row][col]=c; col++; } else { col=0; row++; for(col=0;col<12;col++) { checkary[col]=ary[row][col]; cout<<checkary[col]; cout<<ary[row][col]; } //After word is stored look to see if its already there int checkcol,checkrow; for(checkrow=0;checkrow<86;checkrow++) { checkcol=0; while((checkary[checkcol]==ary[checkrow][checkcol])||(checkary[checkcol]!='\0')) checkcol++; if(checkcol>=11) { row--; col=0; for(checkcol=0;checkcol<12;checkcol++)//Nulls out what was put into that row { ary[row][checkcol]='\0'; } // x=0;//FALSE break; } else row++; col = 0; // x=0; }//end for }//end else }//end while inputFile.close(); for(row=0;row<86;row++) //Prints array { for(col=0;col<12;col++) { cout<< ary[row][col]; } }//end print cout<<"\n"; }//end main |
|
#2
|
|||
|
|||
|
what do u mean by this:
inputFile.get(c); if( c != '\0') { ary[row][col]=c; col++; } else { ..... }// these codes are never executed! cos c=='\0' never succeed! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Help with C style string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|