Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- void ordena(char **palavras, int n){
- int i,j;
- char * aux = (char*)malloc(sizeof(char)*100);
- for(i = 1; i < n; i++){
- for(j = 0; j < n-1; j++){
- if(strcmp(palavras[j],palavras[j+1]) > 0){
- strcpy(aux, palavras[j]);
- strcpy(palavras[j],palavras[j+1]);
- strcpy(palavras[j+1], aux);
- }
- }
- }
- }
- void imprime(char **palavras, int n){
- int i;
- printf("\n");
- for(i = 0; i < n; i++){
- printf("%s\n", palavras[i]);
- }
- }
- int main()
- {
- int n, i;
- char **palavras;
- scanf("%d", &n); // Quantidade palavras
- palavras = (char**)malloc(sizeof(char*) * n); // Aloca linhas
- for(i = 0; i < n; i++){
- palavras[i] = (char*)malloc(sizeof(char) * 100); // Aloca colunas
- }
- for(i = 0; i < n; i++){ // Preenche vetores
- scanf("%s", palavras[i]);
- }
- ordena(palavras, n); // Ordena com o algoritmo bubble sort
- imprime(palavras, n); // Imprime
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement