#include <stdio.h>
#include <stdlib.h>
typedef struct Details{
int num;
char message[100];
}Notes;
void write(FILE*,Notes);
void read(FILE*);
int main()
{
int c;
FILE *fp = fopen("Notes.txt","w+");
Notes txt;
printf("Select choice\n1.Write\n2.Read\n");
scanf("%d",&c);
if(fp == NULL)
printf("Could not able to open the file\n");
else
switch(c){
case 1:
write(fp,txt);
case 2:
read(fp);
}
return 0;
}
void write(FILE* fp,Notes msg)
{
puts("Enter text\n");
fgets(msg.message,20,stdin);
fputs(msg.message,fp);
fclose(fp);
}
void read(FILE* fp)
{
char ch;
do{
ch=fgetc(fp);
printf("%c",ch);
}while(ch != EOF);
fclose(fp);
}
When I run the above code on write case (case 1) fgets() is not taking any inputs from the user via keyboard.
I need the user contents which the user types on the keyboard should be stored in a file and to be read when required.