I am trying to store data from two variables in a text file .. and then try to get the data back and output it on screen but somehow the following program is not working as supposed to be.
I first enter data in the two variables n1 and n2 .
then i open the file to write data to it ..
then i open the file again to read data from it .. (but data isnt outputted well)
#include<stdio.h>
int main()
{
char buffer[3];
int n1, n2;
scanf("%d",&n1);
scanf("%d",&n2);
FILE *input =fopen("lilly.txt","w+");
fprintf(input, "%d\n", n1);
fprintf(input, "%d\n", n2);
fclose(input);
FILE *output =fopen("lilly.txt","r");
printf("\n\nN1 = ");
fgets(buffer, 0, output);
printf("%s", buffer);
printf("\n\n1N2 = ");
fgets(buffer, 1, output);
printf("%s", buffer);
fclose(output);
getchar();
getchar();
return 0;
}