| | |
Is it possible to arange lines in a file alphabetically?
![]() |
•
•
Join Date: Oct 2006
Posts: 23
Reputation:
Solved Threads: 0
OK, so the part of my course about files is over, but now I am wondering: if you have a file with, say, a bunch of names (each in its own line), is it possible to use "C" to make a new file with the names aranged alphabetically? For example, if the original file is:
the new one should be
If it can be done...well, explain how.
P.S. I'm asking because I want to arange my list of music albums, because right now, the names are held in a completely sporadic manner in a Word document.:cheesy:
c Syntax (Toggle Plain Text)
Mike Carl John Babe Ferrari
the new one should be
c Syntax (Toggle Plain Text)
Babe Carl Ferrari John Mike
If it can be done...well, explain how.
P.S. I'm asking because I want to arange my list of music albums, because right now, the names are held in a completely sporadic manner in a Word document.:cheesy:
In the twilight zone we disperse cowards//
vampires that stalk Earth on reverse hours - Jus Allah
And on top of that they still wanna take me to prison//
just cause I won't trade humanity for patriotism - Immortal Technique
vampires that stalk Earth on reverse hours - Jus Allah
And on top of that they still wanna take me to prison//
just cause I won't trade humanity for patriotism - Immortal Technique
•
•
Join Date: Jul 2005
Posts: 1,671
Reputation:
Solved Threads: 261
Read all the lines into a container in your program. Sort the container. Then write the contents of the container back to your file, overwriting the previous unsorted contents of the file. What container you use is up to you based on your knowledge and experience. What sorting algorhythm you use is up to you, too, but choices include bubble sort, quick sort, insertion sort, etc.
A Word file probably has a lot of extraneuous gunk in it to make it pretty when you open the file in Word. If you can save the contents in a plain text file, like you would get with Note Pad, that might be easier to read from, unless you know the specific set up of the Word file. Of course, if you have no trouble reading in the Word file, then you don't have to worry about this paragraph.
A Word file probably has a lot of extraneuous gunk in it to make it pretty when you open the file in Word. If you can save the contents in a plain text file, like you would get with Note Pad, that might be easier to read from, unless you know the specific set up of the Word file. Of course, if you have no trouble reading in the Word file, then you don't have to worry about this paragraph.
Last edited by Lerner; Nov 20th, 2006 at 12:20 pm.
•
•
Join Date: Oct 2006
Posts: 23
Reputation:
Solved Threads: 0
This might sound stupid...but what is a container? Either it's an English word for something I'm familiar with (English isn't my first language) or I simply don't know what it is.
And please name some containers.
Word formatting isn't a problem.
And please name some containers.
Word formatting isn't a problem.
Last edited by Sin-da-cat; Nov 20th, 2006 at 12:32 pm.
In the twilight zone we disperse cowards//
vampires that stalk Earth on reverse hours - Jus Allah
And on top of that they still wanna take me to prison//
just cause I won't trade humanity for patriotism - Immortal Technique
vampires that stalk Earth on reverse hours - Jus Allah
And on top of that they still wanna take me to prison//
just cause I won't trade humanity for patriotism - Immortal Technique
•
•
•
•
P.S. I'm asking because I want to arange my list of music albums, because right now, the names are held in a completely sporadic manner in a Word document.:cheesy:
Word File is not a text editor but used to present text and such tools are not used for storing data. Data files of user either have a header format which the user has designated (like a game's save file) and he knows or they are just pure text with custom extension (names.sdc) .
•
•
•
•
This might sound stupid...but what is a container? Either it's an English word for something I'm familiar with (English isn't my first language) or I simply don't know what it is.
And please name some containers.
THe basic containers are well -- arrays
in C and Vectors in C++.If you using arrays you can use the inbuilt qsort( ) method to sort the array and if you usign vectors you can use the inbuilt sort( ) algorithm.
Last edited by ~s.o.s~; Nov 20th, 2006 at 12:33 pm.
I don't accept change; I don't deserve to live.
•
•
Join Date: Oct 2006
Posts: 23
Reputation:
Solved Threads: 0
<snip>, it was a stupid question.:rolleyes:
I know about Word not being a pure text editor, I was gonna paste it into a notepad file.
Thanks.
I know about Word not being a pure text editor, I was gonna paste it into a notepad file.
Thanks.
Last edited by Ancient Dragon; Nov 20th, 2006 at 3:33 pm.
In the twilight zone we disperse cowards//
vampires that stalk Earth on reverse hours - Jus Allah
And on top of that they still wanna take me to prison//
just cause I won't trade humanity for patriotism - Immortal Technique
vampires that stalk Earth on reverse hours - Jus Allah
And on top of that they still wanna take me to prison//
just cause I won't trade humanity for patriotism - Immortal Technique
•
•
Join Date: Oct 2006
Posts: 23
Reputation:
Solved Threads: 0
c Syntax (Toggle Plain Text)
main(){ FILE *a,*b; char s[100]; int i=0,k; char starr[50][101]; /*50 - the number or strings I wanna put in the array*/ a=fopen("C:\\C_fajlovi\\non_sorted.txt","r"); b=fopen("C:\\C_fajlovi\\sorted.txt","w"); /*made a new file, want to keep the previous one too*/ while(fscanf(a,"%s",&s)!=EOF){ starr[i]=s; i++; } ...
Why do I get 'Lvalue required' when I try to put a string in the array (starr[i]=s)?
And what should I use instead if this brings up an error?
Last edited by Sin-da-cat; Nov 20th, 2006 at 1:43 pm.
In the twilight zone we disperse cowards//
vampires that stalk Earth on reverse hours - Jus Allah
And on top of that they still wanna take me to prison//
just cause I won't trade humanity for patriotism - Immortal Technique
vampires that stalk Earth on reverse hours - Jus Allah
And on top of that they still wanna take me to prison//
just cause I won't trade humanity for patriotism - Immortal Technique
![]() |
Other Threads in the C Forum
- Previous Thread: pthread
- Next Thread: Visual Studio Team System
| Thread Tools | Search this Thread |
#include * ansi api array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o inches include infiniteloop input interest intmain() iso keyboard km linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mysql oddnumber open opendocumentformat openwebfoundation pdf pointer posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send sequential shape single socket socketprogramming stack standard strchr string suggestions test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






