| | |
sorting from a input text file
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
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!!!!!
#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!!!!!
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.
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
![]() |
Similar Threads
- how do I send a text file to a printer connected to the client's computer (ASP.NET)
- Reading numbers from a text file (Java)
- how to read a text file backwards? (C)
- turning userinput into a text file (C)
- Trying to creating an array from a text file (C++)
- sorting a text file (C++)
- Help with comparing user input to a text file! (C++)
- Help Reading Info in Text File Into an Array (C++)
- Text File Input and manipulation (C++)
Other Threads in the C Forum
- Previous Thread: its ny home work pla helpppppppppppp
- Next Thread: fseek64()
Views: 1492 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C
* api append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax database directory drawing dynamic executable execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked reversing scheduling segmentationfault send single socketprogramming spoonfeeding standard strchr string student suggestions system test testautomation testing unix urboc user whythiscodecausesegmentationfault win32api windowsapi






