Hi i'm new to programming and would like to alphabetize my input file
i have a list of names
henry
james
etc
...
but i cannot find any reputable information and my tutors are very bad
Can you please help?
Hi i'm new to programming and would like to alphabetize my input file
i have a list of names
henry
james
etc
...
but i cannot find any reputable information and my tutors are very bad
Can you please help?
The easy way (relatively speaking) is to read the entire file into an array (or linked list) then sort it. If you have an array, the standard qsort() function can be used. For a linked list, you can use insertion sort, although that's slow. A more complex but efficient method to sort a linked list is a merge sort.
You'll have to start by writing some code, though.
first... look up the syntax for strcmp() ... next read up a little on various sorts such as Bubble Sort, Selection Sort, Quick Sort etc...
Basically it's like those sliding tile games where you can only move one tile at a time... you will be scanning your string array, multiple times, deciding when to trade items to move things into order.
There's a ton of information out there, Google is your friend...
Once you get to the point where you have some code, if you get stuck... post your code here and we'll see what we can do.
#include "stdafx.h"
#include <stdio.h>
This reads the data file in question. I am having difficulty finding a decent site for help on sorting functions to alphebetize itCode:int main(void) { FILE *fp ; char ch ; fp = fopen ( "input2a.dat", "r" ) ; while ( 1 ) { ch = fgetc ( fp ) ; if ( ch == EOF ) break ; printf ( "%c", ch ) ; } fclose ( fp ) ; return 0; }
Well first of all you need to read by lines or words... not characters, unless you plan to do a lot of post-processing.
Try to work out how you can read your data file into an array of char strings...
Are you compiling this program in C or C++? Check your project options and see that you are using the compiler you need.
I am writing in c,
I have come to the conclusion that i should quit life and form a suicide pact with everyone else who is going to fail this assignment.
P.s With the code i posted, i have determined that i should be using an array. Taken me 3 hours. No progress.