Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading file

Status
Not open for further replies.

chimpy

Programmer
Apr 16, 2002
1
GB
hi
i am new to c++, i want a user to enter an integer then the program to open a file and search the file for this int, if it doesn't find it, it tells the user so and then carries on, if it does find it then it asks the user to try another int and then searches again from the begining of the file etc..

thanks for any help.

chimpy
 
FILE *file;

file = fopen("c:\\path\\filename", "rb");
if(file == NULL)
{
cant open file
}

while(!feof(file))
{
unsigned char c = fgetc(file);
if(c == users number)
found it
}

Hope that helps. If you want more code then post a reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top