I am trying to insert First Name, Last Name and Phone Number using fprintf to a CSV file. But after the insertion additional strange characters and commas are being inserted at the end of each line, and while reading the file it is creating problems.
Following is my code:
FILE *fp;
fp = fopen(filePath, "r");
int i = 0;
***** Writing *****
FILE *fp;
fp = fopen("input.csv", "a");
fprintf(fp,"%s %s ,%s\n", firstname, lastname , phone_number);
***** Reading *****
while(!feof(fp)){
fscanf(fp, "%s %s,%s", phone_directory[i].First_Name, phone_directory[i].Last_Name, phone_directory[i].Phone_Number);
printf("%s %s,%s\n", phone_directory[i].First_Name, phone_directory[i].Last_Name, phone_directory[i].Phone_Number);
i=i+1;
}
***** Input ******
//First Entry
abc xyz,65656565
//Second Entry
uvw efg,6979679679
***** Output *****
abc xyz,65656565,
, uvw,
efg,6979679679 ,,
,
Please Help!!!