I want to store the data in location but whenever I run the code it give me message that the fp is undeclared. I want fp to be working in another function. How to do this?
#include <stdio.h>
#include <stdlib.h>
#define MAX 15
int new_acc(char *name, size_t namesize);
int list_view(char *name);
int main(){
FILE *fp;
fp = fopen("/home/Documents/file.txt","w"); /* this is fp */
int one='1', two='2';
char choice[MAX], name[15] = "";
do{
printf("%c. Create new account\n",one);
printf("Enter your choice: ");
fgets(choice, sizeof choice, stdin);
if (choice[0] == one)
{new_acc(name, sizeof name);}
}
while(two != choice[0]);
return 0;}
int new_acc(char *name, size_t namesize){
printf("Enter your name: ");
fgets(name, namesize, stdin);
fputs(name, fp);
fclose(fp);
return 0;}