fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct agenda {
  6. char nome[10], email[15]; fone[9];
  7. struct agenda *prox;
  8. }Tagen;
  9.  
  10. void insere(Tagen **L, char nome[]);
  11. Tagen* busca(Tagen *L, char nome[]);
  12. void remover(Tagen **L, char nome[]);
  13. void listar(Tagen *L);
  14. void exibir(Tagen **L, char nome[]);
  15. void alterar(Tagen **L, char nome[]);
  16. void excluir(Tagen **L);//toda lista
  17.  
  18.  
  19.  
  20. int main() {
  21. Tagen *lista = NULL, aux;
  22. char op, nome[10];
  23.  
  24. do {
  25. printf("1-inserir 2-remover 3-exibir 4-alterar contato 5- listar todos os contatos 6-sair\n");
  26. op=getchar(); fflush(stdin);
  27. switch (op) {
  28. case '1':
  29. printf("nome\n");
  30. gets(nome);
  31. insere(&lista, nome);
  32. break;
  33. case '2':
  34. printf("nome\n");
  35. gets(nome);
  36. remover(&lista, nome);
  37. break;
  38. case '3':
  39. printf("nome\n");
  40. gets(nome);
  41. exibir(&lista, nome);
  42. break;
  43. case '4':
  44. printf("nome\n");
  45. gets(nome);
  46. alterar(&lista, nome);
  47. break;
  48. case '5':
  49. listar(lista);
  50. break;
  51. case '6':
  52. printf("FIM de programa\n");
  53. break;
  54. default:
  55. printf("invalido\n");
  56. }
  57. } while (op != '6');
  58. excluir(&lista);
  59.  
  60. return 0;
  61. }
  62.  
  63. void insere(Tagen **L, char nome[]) {
  64. Tagen *novo, *aux1, *aux2;
  65. if (*L == NULL) {
  66. novo = (Tagen*)malloc(sizeof(Tagen));
  67. printf("Digite o fone:\n");
  68. gets(novo->fone);
  69. printf("Digite o email:\n");
  70. gets(novo->email);
  71. strcpy(novo->nome, nome);
  72. novo->prox = NULL;
  73. *L = novo;
  74. }
  75. else if (busca(*L, nome) != NULL) {
  76. printf("contato ja existente\n");
  77. }
  78. else {
  79. if (strcmp((*L)->nome, nome) < 0 && (*L)->prox == NULL) {
  80. novo = (Tagen*)malloc(sizeof(Tagen));
  81. printf("Digite o fone:\n");
  82. gets(novo->fone);
  83. printf("Digite o email:\n");
  84. gets(novo->email);
  85. strcpy(novo->nome, nome);
  86. novo->prox = NULL;
  87. (*L)->prox = novo;
  88. }
  89. else {
  90. aux1 = *L;
  91. aux2 = aux1->prox;
  92. while (aux2 != NULL) {
  93. if (strcmp(aux1->nome, nome) > 0) {
  94. novo = (Tagen*)malloc(sizeof(Tagen));
  95. printf("Digite o fone:\n");
  96. gets(novo->fone);
  97. printf("Digite o email:\n");
  98. gets(novo->email);
  99. strcpy(novo->nome, nome);
  100. aux1->prox = novo;
  101. novo->prox = aux2;
  102. printf("inserido\n");
  103. return;
  104. }
  105. else {
  106. aux1 = aux2;
  107. aux2 = aux2->prox;
  108. }
  109. }
  110. }
  111. }
  112. }
  113.  
  114. Tagen *busca(Tagen *L, char nome[]) {
  115. Tagen *aux;
  116.  
  117. if (L == NULL)
  118. return NULL;
  119. else{
  120. aux = L;
  121. while (L != NULL) {
  122. if (strcmp(aux->nome, nome) == 0)
  123. return aux;
  124. else if (strcmp(aux->nome,nome)>0)
  125. return NULL;
  126. else
  127. L = L->prox;
  128. }
  129. }
  130. return NULL;
  131. }
  132.  
  133. void remover(Tagen **L, char nome[]) {
  134. Tagen *aux1, *aux2;
  135. if (*L == NULL) {
  136. printf("lista vazia");
  137. }
  138. else if ((*L)->prox == NULL) {
  139. if (strcmp((*L)->nome, nome) == 0) {
  140. free(*L);
  141. *L == NULL;
  142. }
  143. else {
  144. printf("contato nao cadastrado\n");
  145. }
  146. }
  147. else {
  148. if (strcmp((*L)->nome, nome) == 0) {
  149. aux1 = *L;
  150. *L = (*L)->prox;
  151. free(aux1);
  152. }
  153. else {
  154. aux1 = *L;
  155. aux2 = aux1->prox;
  156. while (aux2 != NULL) {
  157. if (strcmp(aux2->nome, nome) == 0) {
  158. aux1->prox = aux2->prox;
  159. free(aux2);
  160. return;
  161. }
  162. else {
  163. aux1 = aux2;
  164. aux2 = aux2->prox;
  165. }
  166. }
  167. }
  168. }
  169. }
  170.  
  171. void listar(Tagen *L) {
  172. if (L == NULL) {
  173. printf("Vazia\n");
  174. }
  175. else {
  176. while (L != NULL) {
  177. puts(L->fone);
  178. puts(L->nome);
  179. puts(L->email);
  180. L = L->prox;
  181. }
  182. }
  183. }
  184.  
  185. void exibir(Tagen **L, char nome[]) {
  186. Tagen *aux;
  187. aux = busca(*L, nome);
  188. if (aux == NULL) {
  189. printf("contato nao achado\n");
  190. }
  191. else {
  192. puts(aux->fone);
  193. puts(aux->nome);
  194. puts(aux->email);
  195. }
  196. }
  197.  
  198. void alterar(Tagen **L, char nome[]) {
  199. Tagen *aux;
  200. aux = busca(*L, nome);
  201. if (aux == NULL) {
  202. printf("contato nao achado\n");
  203. }
  204. else {
  205. printf("Digite o numero\n");
  206. scanf("%d", &aux->fone);
  207. printf("digite o email\n");
  208. gets(aux->email);
  209. }
  210. }
  211.  
  212. void excluir(Tagen **L) {
  213. Tagen *aux; aux = *L;
  214. if (*L != NULL) {
  215. while (*L != NULL) {
  216. aux = *L; *L = (*L)->prox;
  217. free(aux);
  218. }
  219. }
  220. }
Compilation error #stdin compilation error #stdout 0s 10320KB
stdin
Standard input is empty
compilation info
prog.c:6:28: error: expected specifier-qualifier-list before ‘fone’
  char nome[10], email[15]; fone[9];
                            ^~~~
prog.c: In function ‘main’:
prog.c:30:4: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration]
    gets(nome);
    ^~~~
prog.c:21:23: warning: unused variable ‘aux’ [-Wunused-variable]
  Tagen *lista = NULL, aux;
                       ^~~
prog.c: In function ‘insere’:
prog.c:68:12: error: ‘Tagen {aka struct agenda}’ has no member named ‘fone’; did you mean ‘nome’?
   gets(novo->fone);
            ^~
prog.c:72:7: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
   novo->prox = NULL;
       ^~
prog.c:79:43: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
   if (strcmp((*L)->nome, nome) < 0 && (*L)->prox == NULL) {
                                           ^~
prog.c:82:13: error: ‘Tagen {aka struct agenda}’ has no member named ‘fone’; did you mean ‘nome’?
    gets(novo->fone);
             ^~
prog.c:86:8: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
    novo->prox = NULL;
        ^~
prog.c:87:8: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
    (*L)->prox = novo;
        ^~
prog.c:91:15: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
    aux2 = aux1->prox;
               ^~
prog.c:96:14: error: ‘Tagen {aka struct agenda}’ has no member named ‘fone’; did you mean ‘nome’?
     gets(novo->fone);
              ^~
prog.c:100:10: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
      aux1->prox = novo;
          ^~
prog.c:101:10: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
      novo->prox = aux2;
          ^~
prog.c:107:17: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
      aux2 = aux2->prox;
                 ^~
prog.c: In function ‘busca’:
prog.c:127:10: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
     L = L->prox;
          ^~
prog.c: In function ‘remover’:
prog.c:138:15: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
  else if ((*L)->prox == NULL) {
               ^~
prog.c:141:7: warning: statement with no effect [-Wunused-value]
    *L == NULL;
       ^
prog.c:150:13: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
    *L = (*L)->prox;
             ^~
prog.c:155:15: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
    aux2 = aux1->prox;
               ^~
prog.c:158:10: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
      aux1->prox = aux2->prox;
          ^~
prog.c:158:23: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
      aux1->prox = aux2->prox;
                       ^~
prog.c:164:17: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
      aux2 = aux2->prox;
                 ^~
prog.c: In function ‘listar’:
prog.c:177:10: error: ‘Tagen {aka struct agenda}’ has no member named ‘fone’; did you mean ‘nome’?
    puts(L->fone);
          ^~
prog.c:180:9: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
    L = L->prox;
         ^~
prog.c: In function ‘exibir’:
prog.c:192:11: error: ‘Tagen {aka struct agenda}’ has no member named ‘fone’; did you mean ‘nome’?
   puts(aux->fone);
           ^~
prog.c: In function ‘alterar’:
prog.c:206:19: error: ‘Tagen {aka struct agenda}’ has no member named ‘fone’; did you mean ‘nome’?
   scanf("%d", &aux->fone);
                   ^~
prog.c: In function ‘excluir’:
prog.c:216:23: error: ‘Tagen {aka struct agenda}’ has no member named ‘prox’
    aux = *L; *L = (*L)->prox;
                       ^~
stdout
Standard output is empty