ok I fixed it.
All of the code...
bare with my formatting.
Code:
#include <stdio.h>
main()
{
int line = 1;//tell what line it is on
int found = 0;
char liner[100];//put the characters of the line into here
int linesearch;//the line you are looking for
FILE *file;//the file pointer
file = fopen("C:\\Users\\bob\\Desktop\\hl2\\portal_config.cfg","r");//point the file
if (file == NULL)
{
printf("file does not exist or doesn't work\n");
return 0;
}
printf("line number:");//print line number...
scanf("%d",&linesearch);//...then scan after the printf
printf("\ngoing to line %d\n\n",linesearch);//to make it look like programs in TV shows
while(fgets(liner,100,file))//read the file string by string
{
if(linesearch == line)
{
found = 1;
printf("line %d found,line %d says: %s",linesearch,linesearch,liner);
}
printf("reading line: %d\n",line);//when a line is read tell what line it is for debug perposes.
line++;//make 'line' go up once
}
if (found == 0)
{
printf("line number %d was not found",linesearch);
}
line = line - 1;
printf("\nthis file has: %d lines",line);
getch();//getch to see what was printed out.
}
Tell me if you find any more errors