I have some code that reads in the user input into a struct, how ever i want to print this input into a text file but i have no idea how to do that. I have the code for the user input but i think i need to put this into a loop so it reads the input into the .txt file. Can any one help?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
//declaring the struct
struct customer
{
int ID;
int age;
char gender;
char name [40];
char surname [40];
char address [100];
};//end to customer sturucture
FILE *fpcust; //declaring a file variable pointer for customers txt file
struct customer new_customer;
char ch;
int ID [20];
int i;
fp = fopen ("c:\\customers.txt", "w"); //opening file for writing
if (fp == NULL) //error check
{
printf("Cannot open file. \n");
}
//structure for reading the new customer
printf("Please enter your ID. \n");
scanf("%d", &new_customer.ID);
printf("Please enter your age. \n");
scanf("%d%*c", &new_customer.age);
printf("Please enter your gender. ( m or f ) \n");
scanf("%c%*c", &new_customer.gender);
printf("Please enter your firstname. \n");
gets(new_customer.name);
printf("Please enter your surname. \n");
gets(new_customer.surname);
printf("Please enter your address. \n");
gets(new_customer.address);
fclose(fp); //closing the file
}