944,184 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2235
  • C RSS
Oct 14th, 2007
0

sorting from a input text file

Expand Post »
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!!!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pedro martinez is offline Offline
2 posts
since Oct 2007
Oct 14th, 2007
0

Re: sorting from a input text file

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.
Last edited by Aia; Oct 14th, 2007 at 8:22 pm.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: its ny home work pla helpppppppppppp
Next Thread in C Forum Timeline: fseek64()





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC