I have this code:
#include <stdio.h>
int create_logfile(char *name, char *field, char *joindate)
{
FILE *ofile;
ofile = fopen("test.txt", "a+");
if(ofile == NULL)
return 1;
fprintf(ofile, "%s\t%s\t[%s]\n", name, field, joindate);
fclose(ofile);
return 0;
}
int main()
{
char name[100], field[100], joindate[100];
printf("Name: ");
fgets(name, sizeof(name), stdin);
printf("Field: ");
fgets(field, sizeof(field), stdin);
printf("Date: ");
fgets(joindate, sizeof(joindate), stdin);
create_logfile(name, field, joindate);
}
It gives this output:
John Doe
Programmer
[15/06/96
]
But is supose to give it like this:
John Doe Programmer [15/06/96]
What is worng and how do i fix it?