Nov 11, 2012 at 11:30am UTC
This is my code for sort char array...how to sort Z-A
I use 2d char array named nazivi...
for (int i=0;i<br_unesenih_el;i++)
for(int j=i;j<=br_unesenih_el;j++)
if((strcmp(nazivi[j],nazivi[i]))>0)
{
strcpy(temp,nazivi[i]);
strcpy(nazivi[i],nazivi[j]);
strcpy(nazivi[j],temp);
/*pomocna = polje_cijena[i];
polje_cijena[i]=polje_cijena[j];
polje_cijena[j]=pomocna;
pomocna2 = polje_sifra[i];
polje_sifra[i]=polje_sifra[j];
polje_sifra[j]=pomocna2;*/
}
Last edited on Nov 11, 2012 at 11:50am UTC
Nov 11, 2012 at 12:14pm UTC
Add comments (English only) into your snippet code.
Also you should put your snippet code into <> format tag.
Nov 11, 2012 at 2:05pm UTC
1- Sort all characters in an array or multiple arrays?
2-
br_un... -> len
nazivi -> str
Agree?
Nov 11, 2012 at 2:26pm UTC
char nazivi[1000][20] -> user writes names in this array....
br_un... -> number of names....
With this code i can sort A-Z...How can i change this code to sort Z-A?
Please help...
Nov 11, 2012 at 2:38pm UTC
This strange algorithm is harder than I and (you thought).
You only need the first character of all names to be sorted, or all perfectly??
You should have a multiple layered checking loops, per loop range : 1 character, and counting.
Maybe I'll provide an example later but you should follow this advice and try thinking yourself... :)
Good Luck!!!
Last edited on Nov 11, 2012 at 2:40pm UTC
Nov 11, 2012 at 2:39pm UTC
Do you know simply example code for this?
I need all all perfectly....
example... user input jackson, arny and bony...and program print jackson, bony, arny
I need just this part of code change (or some better example)
Last edited on Nov 11, 2012 at 2:43pm UTC