Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAXWORDS 30
- #define MAXNAME 50
- int main()
- {
- int position = 0,i,j,k;
- char names[MAXNAME][MAXWORDS],test[MAXWORDS];
- while (1) {
- printf("Entre com um nome: (tecle 'Fim' para sair)\n");
- gets(test);
- if (strcmp(test,"Fim") == 0 || strcmp(test,"fim") == 0)
- break;
- else {
- strcpy(names[position],test);
- position++;
- }
- }
- k = position-1;
- for (i = 0; i < position; i++){
- for (j = 0; j < k; j++) {
- if (strcmp(names[j],names[j+1]) > 0) {
- strcpy(test,names[j]);
- strcpy(names[j],names[j+1]);
- strcpy(names[j+1],test);
- }
- }
- k--;
- }
- printf("Lista ordenada alfabeticamente :\n");
- for (i = 0; i < position; i++)
- puts(names[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment