sorting from a input text file

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 2
Reputation: pedro martinez is an unknown quantity at this point 
Solved Threads: 0
pedro martinez pedro martinez is offline Offline
Newbie Poster

sorting from a input text file

 
0
  #1
Oct 14th, 2007
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!!!!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,048
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 179
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: sorting from a input text file

 
0
  #2
Oct 14th, 2007
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.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1492 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC