int main(void)
{
FILE* cfPtr;
fopen_s(&cfPtr, "clients.txt", "w");
if (cfPtr == NULL) {
puts("File could not be opened.");
}
else {
puts("Enter the account ID, name, and phone number.");
puts("Enter EOF to end input.");
printf("%s", "> ");
char id[10];
char name[30];
char phone[16];
scanf_s("%9s%29s%15s", id, 10, name, 30, phone, 16);
while (!feof(stdin)) {
fprintf(cfPtr, "%s %s %s\n", id, name, phone);
printf("%s", "> ");
scanf_s("%9s%29s%15s", id, 10, name, 30, phone, 16);
}
fclose(cfPtr);
}
}
I'm trying to print three strings into a file. The code above works fine for strings id and name but for the phone it just prints 0 in the file and for some reason the format is incorrect, it writes phone before name. When it should've been: id name phone