26 lines
444 B
C
26 lines
444 B
C
// Saves names and numbers to a CSV file
|
|
|
|
#include <cs50.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main(void)
|
|
{
|
|
// Open CSV file
|
|
FILE *file = fopen("phonebook.csv", "a");
|
|
if (!file)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
// Get name and number
|
|
char *name = get_string("Name: ");
|
|
char *number = get_string("Number: ");
|
|
|
|
// Print to file
|
|
fprintf(file, "%s,%s\n", name, number);
|
|
|
|
// Close file
|
|
fclose(file);
|
|
}
|