Advertisement
justaCprogrammer

loopcomswitchcomstruct.c

Dec 12th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. struct nomesL{
  5. char string[100];
  6. };
  7. int main(){
  8. int x,resp;
  9. int trava,cont;
  10. trava = trava + 1;
  11. do{
  12. printf("Por favor selecione uma opcao\n");
  13. printf("[1]Adicione mais um nome a lista\n");
  14. printf("[2]Encerrar o Programa\n");
  15. scanf("%d",&resp);
  16. switch (resp){
  17. case 1:
  18. x = x + 1;
  19. struct nomesL pessoas[x];
  20. int cont;
  21. char **str;
  22. str = malloc(x * sizeof(char*));
  23. for(cont = 0;cont < x;cont++){
  24. printf("Digite o nome\n");
  25. str[cont] = malloc(100);
  26. fgets(str[cont],100,stdin);
  27. system("cls");
  28. }
  29. for(cont = 0;cont < x;cont++){
  30. strcpy(pessoas[cont].string, &str[cont]);
  31. printf("%s\n",pessoas[cont].string);
  32. }
  33. break;
  34. }
  35. trava + 1;
  36. }while(trava);
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement