Your char arrays need to be 8 characters long (bytes) to store the information read from the file. In fact you would do better to read the file and store one line at a time, so you would need to have another array of char to hold that value. Have a look at the cstring function strncpy.
Code:
void SearchClass()
{
char input[8];
char course[8];
char lineread[50];
int i;
cout<<"enter in course to search: ";
cin>>course;
fstream readfile;
readfile.open("C:/WINDOWS/Desktop/class.txt", ios::in);
// reads line of text from file
readfile.getline(lineread, 50);
while(!readfile.eof())
{
// copies first 7 characters into input from line read
strncpy(input, lineread, 7);
// ensures null terminated
input[7] = '\0';
// "\n" puts each result on one line
if(strcmp(course, input)==0)
{cout<<"match\n";}
else
{cout<<"no match\n";}
readfile.getline(lineread, 50);
}
readfile.close();
}
I havenot tested this as have no compiler here at moment, but you should get the jest of whats happening. You should have test to ensure the file opens to read ok and also some way of ensuring the user inputs only the seven character course number.