I am using structures of arrays, and one of the arrays holds football teams. I want to organise the data alphabetically, and have it displayed. Can this be done?
I am using structures of arrays, and one of the arrays holds football teams. I want to organise the data alphabetically, and have it displayed. Can this be done?
Hmmm. So if I am correct you have a structure with arrays as members and one of the arrays contains the names of football teams. And you want to organise that array alphabetically. Yes, that is possible, you could sort the array and then print it out. You can use qsort, part of the standard library, to sort the array.
Hi I am very new to C, I need help with:
-prompting the user for a string of up to 10 characters.
-the output should be all alphabetic characters from string converted to lower case and sorted in ascending order.
#define MAX_STRING 10
#define EXTRA_CHARS 2
printf( "Sort Line\n");
printf("%s", "-------\n");
printf ("Please enter a string (1-10 characters):\n");
sscanf("%s", &a);
char a[MAX_STRING];
fgets(a, MAX_STRING+EXTRA_CHARS, stdin);
SORT_LINE;
for (i >= a; i<= z; i++);
{
Last edited by beginner to c; 03-08-2011 at 08:54 PM.
Edit your post and add code tags.
Why is 'MAX_STRING' 10, but you say "enter 1 - 40 characters"?
Quzah.
Hope is the first step on the road to disappointment.
Thing's you'll probably need:
tolower function - will convert an upper-case character to lower-case. So you'll probably need to loop through your string and call the tolower function on each character.
A sorting algorithm - try Bubble sort - Wikipedia, the free encyclopedia
Remember - a string in C is just an array of characters.
Originally Posted by Plato
void sortData(char* string[MAX])
{
///////////////////////////LOCAL DECLARATIONS/////////
int current; int walker;
int smallestIndex;
char* temp;
///////////////////////////DEFINITIONS//////////////////
for (current = 0; current <MAX - 1; current++)
{
smallestIndex = current;
for (walker = current; walker < MAX; walker ++)
{
if (strcmp(string[walker], string[smallestIndex]) < 0)
smallestIndex = walker;
}//for walker
//Swap to position smallest at what is the current position
temp = string[current];
string[current] = string[smallestIndex];
string[smallestIndex] = temp;
}//for current
return;
}
Start your own thread instead of hijacking another persons, especially considering that it is over nine years old!
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
I said that I am new and had no idea of taking any body's thread or bothering anyone!
please forgive me and I will never use this website with such weird educated people!
good luck