Advertisement
Sam-Sampaio

Corrigindo

Aug 30th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define TAM 2
  4.  
  5. void showWords(char** words, int amount);
  6.  
  7. int main()
  8. {
  9.     char **palavras = malloc(TAM*sizeof(void *));
  10.  
  11.      for(int i = 0; i < 2; i++)
  12.           palavras[i] = malloc(100);
  13.      
  14.  
  15.      int i;
  16.     for(i = 0; i < TAM; i++){
  17.         printf("Digite uma palavra: ");
  18.         scanf("%[^\n]s", palavras[i]);
  19.         setbuf(stdin, NULL);
  20.     }
  21.     for(i = 0; i < TAM; i++){
  22.         printf("\n%s\n", palavras[i]);
  23.     }
  24.     showWords(palavras, 2);
  25.  
  26.     for(int i = 0; i < 2; i++)
  27.         free(palavras[i]);
  28.    
  29.      free(palavras);  
  30.  
  31.     return 0;
  32. }
  33. void showWords(char** words, int amount)
  34. {
  35.      int iterator;
  36.     for(iterator = 0; iterator < amount; iterator++){
  37.         printf("%s\n", words[iterator]);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement