Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- char arr[6][4] = {"egg","dog","cat","ba","az","ant"};
- int i;
- printf("original: ");
- for(i=0;i<6;i++){
- printf("%s ",arr[i]);
- }
- printf("\n");
- char temp[4];
- int j;
- for(i=0;i<6-1;i++){
- for(j=0;j<6-1;j++){
- if(strcmp(arr[j],arr[j+1]) > 0){
- strcpy(temp,arr[j]);
- strcpy(arr[j],arr[j+1]);
- strcpy(arr[j+1],temp);
- //cannot use temp = arr[j]
- //but can use strcpy(temp,arr[j]);
- }
- }
- }
- printf("dictionary sorted: ");
- for(i=0;i<6;i++){
- printf("%s ",arr[i]);
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement