Here's my code:
#include <stdio.h>
#include <string.h>
int main(void)
{
int more = 1;
char first[15], last[20];
FILE *file;
file = fopen("user_name_list.txt", "a+");
if(file == NULL)
{
printf("Error: can't open file.\n");
return 1;
}
fprintf(file, "Last First\n"
"--------------\n");
while (more == 1)
{
char line[20];
printf("\nEnter your first and last name separatted by a space> ");
fgets(line, sizeof(line), stdin);
sscanf(line, "\n%s %s", first, last);
printf("\n%s, %s", last, first);
fprintf(file, "\n%s, %s", last, first);
printf("\nAre there more names to be added? (enter '1' for yes or '2' for no)> ");
scanf("%d", &more);
}
return 0;
}
thank you all for the helpMike
Edited by WingedPanther, 31 March 2010 - 11:43 AM.
add code tags (the # button)


Sign In
Create Account

Back to top









