I'm writing a program that imports files from a .csv. They problem is that every item in the file is separated by spaces instead of commas. I know I need to wrtie an if statement to check for commas, but how would I go about doing that and what would I do once that statement found a comma?
Here's my code so far. This is just a subclass so some of the variables you see will not have initializations, but I assure you that they are there.
I apologize in advance for the formatiing; code doesn't copy to messagebaords well.
Code:
void import(){
FILE *in = NULL;
char import[256];
int z = 0;
printf("Enter the number entries contained in the file: ");
scanf("%d", &num);
//getting the file name
printf("Enter the name of the file you wish to import: ");
scanf("%s", &import);
in = fopen (import, "r");
//adding the data to a link list
while (z < num) {
ptr = (Node*)malloc(sizeof(Node));
fscanf(in, "%s %s\n", ptr->lname, ptr->fname);
ptr->unique = z;
//putting it all into one variable
ptr->nextPtr = NULL;
if (firstPtr == NULL)
firstPtr = ptr;
else
lastPtr->nextPtr = ptr;
lastPtr = ptr;
z = z + 1;
}
fclose(in);
printf("File imported successfully!\n");
printf("%s", ptr->lname);
printf("%s", ptr->fname);