| | |
Is it possible to arange lines in a file alphabetically?
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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,757
Reputation:
Solved Threads: 283
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.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
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
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
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
Dont use direct assignment operator. You can't treat strings like normal data types in terms of assignment.
You need to use
You need to use
strcpy to do somthing like that. I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Other Threads in the C Forum
- Previous Thread: pthread
- Next Thread: Visual Studio Team System
Views: 5928 | Replies: 34
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework inches include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue number oddnumber odf opendocumentformat opensource overwrite owf pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






