File tree 2 files changed +38
-0
lines changed 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+
5
+
6
+ typedef struct no {
7
+ char nome_fruta [20 ];
8
+ struct no * proxima ;
9
+ }No ;
10
+
11
+ No * adiciona_fruta (No * lista , char * nome_fruta ){
12
+ No * nova_fruta = (No * ) malloc (sizeof (No ));
13
+ if (nova_fruta == NULL ){
14
+ printf ("No memory!\n" );
15
+ exit (1 );
16
+ }
17
+ strcpy (nova_fruta -> nome_fruta ,nome_fruta );
18
+ nova_fruta -> proxima = lista ;
19
+ return nova_fruta ;
20
+ }
21
+
22
+ void imprime_Lista_frutas (No * lista ){
23
+ No * contador ;
24
+ for (contador = lista ; contador != NULL ; contador = contador -> proxima ){
25
+ printf (" %s -> " , contador -> nome_fruta );
26
+ }
27
+ }
28
+
29
+ int main (void ){
30
+ No * lista_de_frutas ;
31
+ lista_de_frutas = NULL ;
32
+ lista_de_frutas = adiciona_fruta (lista_de_frutas , "Morango" );
33
+ lista_de_frutas = adiciona_fruta (lista_de_frutas , "Abacate" );
34
+ lista_de_frutas = adiciona_fruta (lista_de_frutas , "Goiaba" );
35
+ imprime_Lista_frutas (lista_de_frutas );
36
+ printf ("Null" );
37
+ return 0 ;
38
+ }
You can’t perform that action at this time.
0 commit comments