Can someone tell me what I am doing wrong here?
One of the issues I face w/ my code is that strings are overwriting each other.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int month, date, year;
int main_exit;
struct date
{
int month, date, year
};
struct
{
char name[60];
char address[60];
char citizenship[15];
double phone;
float amt;
char acc_type[10];
struct date dob;
struct date deposit;
struct date withdraw;
int acc_no;
int age;
} add, check;
int main()
{
FILE *fptr;
fptr = fopen("record_data.txt", "a+");
account_no:
printf("\n\n\t\tADD RECORD ");
printf("\n\n\t\tEnter today's date : ");
scanf("%d/%d/%d", &add.deposit.date, &add.deposit.month, &add.deposit.year);
printf("\n\n\t\tEnter AccountNumber : ");
scanf("%d", &check.acc_no);
while (fscanf(fptr, " %d %s %d/%d/%d %d %s %s %lf %s %f %d/%d/%d\n", &add.acc_no, add.name, &add.dob.month, &add.dob.date, &add.dob.year, &add.age, &add.address, &add.citizenship, &add.phone, &add.amt, &add.acc_type) != EOF)
{
if (check.acc_no == add.acc_no)
{
printf("Account no. already in use!");
goto account_no;
}
}
add.acc_no = check.acc_no;
printf("\n\n\t\tEnter the name : ");
fgets(add.name,sizeof(add.name) , stdin);
printf("\n\n\t\tEnter the age : ");
scanf("%d", &add.age);
printf("\n\n\t\tEnter address : ");
scanf("%s", add.address);
printf("\n\n\t\tEnter citizenship number : ");
scanf("%s", &add.citizenship);
printf("\n\n\t\tEnter phonenumber ; ");
scanf("%lf", &add.phone);
printf("\n\n\t\tEnter the amount to deposit : ");
scanf("%f", &add.amt);
printf("\n\n\t\tType of account : ");
scanf("%s", &add.acc_type);
fprintf(fptr, "%d %s %d/%d/%d %d %s %s %lf %s %f %d/%d/%d", add.acc_no, add.name, add.age, add.address, add.citizenship, add.phone, add.amt, add.acc_type);
fclose(fptr);
printf("Account created successfully!");
What I have tried:
I don't know why but my strings are overwriting each other because of that I am not able to run other part of my program.
Also , lemme know if u see errors related to file handling.