On top of solving your current problem and also being easier to use... there is no chance of buffer overflow and memory corruption if a user enters a string longer than 50 characters.
I am not allowed to use strings, only arrays of characters. Since everyone keeps suggesting using string, I'm going to do it anyway. Maybe the instructor won't notice.
But if there's a good way to do this with a char array, I'm listening!
Well that did the trick! Thanks! Now my problem has to do with nested EOF statements. By the time the first loop gets a chance to look at the file a second time, the second loop has apparently already taken it to the end of the file.
void testStrings( char fileName [] ) {
ifstream infile;
ofstream outfile;
char str1 [51];
char str2 [51];
char bigArray [1001] [51];
infile.open (fileName);
for (int i=1; infile.peek() != EOF; i++ ) {
infile >> str1; //string to compare against
do {
infile >> str2; // gets compared to str1
if (strcmp (str1, str2) < 0){
for ( int j=0; j<51; j++) {
bigArray [i][j] = str1[j];
}
//strcpy(str1[n],tempBuffer);
}
} while (infile.peek() != EOF);
cout << "\n 1. " << bigArray[i];
}
}
**************************
* FILE READ/COPY/ANALYZE *
**************************
This program will read in a file, copy it
and create a file containing data about the file.
Enter a file name to be displayed and copied: test.txt
Okay: Copying file: test.txt to new file: Copy of test.txt
Reading: I'll have a Sam Adams.
Reading: It's 9:30 in the morning.
Reading: Come to think of it, I'll have a Sam Adams also.
There were 3 lines read
Copying: I'll have a Sam Adams.
Copying: It's 9:30 in the morning.
Copying: Come to think of it, I'll have a Sam Adams also.
There were 3 lines copied
Reading: I'll have a Sam Adams.
Reading: It's 9:30 in the morning.
Reading: Come to think of it, I'll have a Sam Adams also.
There were 3 lines read
Number of words contained in file: 21
1. I'll
Process returned 0 (0x0) execution time : 1.964 s
Press any key to continue.