Hi all
New to c programming , please feel to modofy my code below...this is what i want to do,
1. i want to read a file and update this file once the user has input the number..
2. i want to show the contents of the file with the user input entered..
required output..
1,2,3,4,5,6,7,8,9,10 - u have entered no. 3
below 2 code snippets can read a file and accept input from user but i can not list the whole file contents...
Code:
#include <stdio.h>
#define MAX 20
char string[20];
int main()
{
FILE *f;
int x;
f=fopen("file.txt","r");
if (!f)
{ printf("Couldn't open file....try again !! txt\n");
return 1;
}
while(fgets(string, 20, f))
{
printf("%s", string);
}
fclose(f);
return 0;
}
above code lists the whole contents of the file....(a.out), how can i modify it so that i can prompt the user to input the number and then print the whole file...can this be done...how...thanks in advance....indy