954,224 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

sorting from a input text file

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
#include

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!!!!!

pedro martinez
Newbie Poster
2 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Pedro, welcome to the forum.
If I understand you correctly what you need is to parse the lines into individual tokens.
Take a look at this tutorial .
Next time make sure you encase your code in:[code]and[/ code]tags. (without the space between / and code).
That will ensure proper format of the code and easiness of read.

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You