In this code, the problem which I am facing is whenever I try to use
scanf after
printf("Enter your choice: ");
in first part and
printf("Enter your name: ");
in second part, it does not allow me to
fputs("Select your choice to update: ", stdout);
execute this code further. It stops there but whenever I use
fgets it gives message of
printf("Access Denied. Please enter correct Details.\n");
How to solve this problem.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 15
#define STRING_LEN 50
int update_info(FILE * fr1, FILE * fr2, FILE * fr3, FILE * fw1, char *name, int *dob);
char one='1', two='2', three='3', four='4', five='5', six='6', seven='7', eight='8', choice[MAX];
static const char * listing[] = {"Name", "Date of birth","ID card number","Phone number","Address","Account","Fixing year","Deposit amount"};
int main(){
FILE * fw1 = fopen("new.csv","w");
FILE * fr1 = fopen("file.csv", "r");
FILE * fr2 = fopen("file.csv", "r");
FILE * fr3 = fopen("file.csv","r");
int dob[11];
char name[15] = "";
while(one != choice[0]){
printf("%c. Create new account\n",one);
printf("%c. Update information\n",two);
printf("Enter your choice: ");
scanf("%7s", &choice);
if (choice[0] == one){
printf("Selected One");
break;
}
else if (choice[0] == two){
update_info(fr1, fr2, fr3, fw1, name, dob);
break;
}
else{
printf("Please enter the correct information\n");
break;
}
}
return 0;
}
Next part
int update_info(FILE * fr1, FILE * fr2, FILE * fr3, FILE * fw1, char *name, int *dob){
int option, i=0, one_by_one;
char file_text[100], updated_name[50], str[100], string[STRING_LEN], input[STRING_LEN], saved_word[STRING_LEN];
char* word = NULL;
short int FLAG = 0;
printf("Enter your name: ");
scanf("%s", &str);
while(fscanf(fr1, "%s", file_text) != EOF){
if(!strcmp(file_text, str)){
printf("Found. Here are your details. \n");
FLAG = 1;
}
}
if (!(FLAG == 1)){
printf("Access Denied. Please enter correct Details.\n");
return -1;
}
fclose(fr1);
int c = fgetc(fr2);
while(c != EOF){
file_text[one_by_one] = c;
if(file_text[one_by_one] == ','){
file_text[one_by_one] = '\0';
printf("Here is your %s: %s\n",listing[i],file_text);
one_by_one = 0;
i++;
}
else
one_by_one++;
c = fgetc(fr2);
}
fclose(fr2);
for (option = 1; option <= sizeof(listing)/sizeof(char *); ++option)
printf("%d. Your %s\n", option, listing[option-1]);
fputs("Select your choice to update: ", stdout);
scanf("%d", &option);
if (option == 1){
while(fgets(string, STRING_LEN-1, fr3)){
printf("Scanned now.\n");
}
}
return 0;
}
What I have tried:
You can check it and its working fine but two problems I am not understanding.