This this is what I have so far. I am trying to sort these name alphabetically. So the output should be "Barney, Dino, Fred, Pebbles, Dino"
Also I have to use strcmp.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main ()
{
char str[10][10];
int i = 0;
int j = 0;
int temp = 0;
strcpy(str[0], "Fred");
strcpy(str[1], "Barney");
strcpy(str[2], "Wilma");
strcpy(str[3], "Pebbles");
strcpy(str[4], "Dino");
for(i = 0;i < 5;i++){
printf("%s,", str[i]);
}
printf("\n\n");
system("PAUSE");
return 0;
}
I have done something similar with numbers, but never with strings.
Code:
int main (){
int arr[10] = {94, 36, 19, 8, 62, 49, 21, 53, 1, 88};
int i = 0;
int j = 0;
int temp = 0;
for(i = 0;i < 10;i++){
for(j = 0; j < 9;j++){
if(arr[j] > arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
for(i = 0;i < 10;i++){
printf("%d,", arr[i]);
}
printf("\n\n");
system("PAUSE");
return 0;
}
I would appreciate any ideas or types. So far I have only been able to move individual letters instead of the entire names. Thanks.