Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct
{
char studentname[50];
int studentid;
} database;
int main(int argc, char *argv[])
{
database school;
FILE *file_ptr;
char text[50];
int temp;
while(1)
{
printf("\nEnter Student Name: ");
scanf("%s", &school.studentname);
if(school.studentname == 0)
{
break;
}
printf("\nEnter Student ID: ");
scanf("%s", &school.studentid);
printf("\nHere is your input Data: %s, %s\n", school.studentname , school.studentid);
printf("\nAdd to school.csv ?(y/n) : ");
getchar();
scanf("%c", &temp);
if(temp == 'y' || temp == 'Y')
{
file_ptr = fopen("school.csv" , "a");
printf("\nFile school.csv opened\n");
fprintf(file_ptr, "%s, %s\n", school.studentname , school.studentid);
fclose(file_ptr);
printf("File Saved.\n");
}
else
{
printf("\nFile not Saved.");
}
}
system("PAUSE");
return 0;
}
Gets Name
Gets ID
Output Name, ID
Prompt to save
if y or Y, save to school.csv
loop until 0
but its crashing when I input ID (id are typically D0124331)