Hi, I need help to sort a file. I am able to open the file, but the lines of the text file are separate by commas and I have to separate the lines into 4 differents string of characters. I have problems separating the string and sorting them by name. Here is waht i have so far,
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char fname[30];
char line[55];
char line1[55];
char line2[55];
char line3[55];
char line4[55];
char title[35];
char date [10];
char rating [10];
int lenght;
FILE *movies;
printf("Enter the name of the file: ");
scanf("%s",fname);
if ((movies = fopen( fname, "r")) == NULL)
{
printf("File could not be opened.\n");
}
else
{
printf("You got it\n");
}
//while(!feof(movies))
//{
// fscanf(movies,"%[^\n]s",line);
//printf("%s\n",line);
for(int i=0;i<=10;i++)
{
fscanf(movies,"\n%[^\n]s",line1);
printf("%s\n",line1);
//fscanf(movies,"%[^,]s",title);
//printf("%s",title);
}
//printf("%s\n",line2);
// printf("%s\n",line3);
// printf("%s\n",line4);
// fscanf(movies,"%[^,]s",lenght);
// printf("%s\n",date);
//}
fclose(movies);
system("PAUSE");
return 0;
}
Please help me!!!!!