Start New Discussion within our Software Development Community

Please help me...
Sir/Ma'am I think I got this one working using this code but I have one problem:
this is the code:

void main()
FILE *fp;
char code[80],code2[80], ename[80];
int elevel;
if((fp = fopen("samplete.txt","r"))==NULL) {
printf("cannot open file.\n");

printf("Enter ID: ");

 while(!feof(fp)) {

    fscanf(fp,"%s %s %d",code,ename,&elevel);

        if(strcmp(code2,code)) {
           printf("%s %s %d",code,ename,elevel);

The problem is it only display the first record or first line of text in my notepad file

lets say when I Enter the ID: ST-0002

it only display the first record or the first line of text file which is: ST-0001, Eddie_VanHalen, 1

it should be: ST-0002, James_Hatfield, 2

Please help me... thanks in advanced

...but I have one problem

No, you have many problems.
1) Using bold, underline, red text, lines of hyphens to make your post look cute. It's unnecessary and distracting. By the way, you forgot to use italics.
2) Your formatting is bad -- see this
3) void main() -- main() is never a void, see this
4) clrscr(); -- useless and annoying for the user, and hasn;t been available in compilers since 1990

if((fp = fopen("samplete.txt","r"))==NULL) {
printf("cannot open file.\n");

What happens if it can't open the file? You continue anyway
6) gets(code2); -- extremely dangerous, see this
7) while(!feof(fp)) -- error prone loop, see this

You might want to learn from a better source. Your current source seems to be older than the hills, and is teaching very bad techniques.

This article has been dead for over six months. Start a new discussion instead.