-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
47 lines (37 loc) · 811 Bytes
/
Copy pathmain.c
File metadata and controls
47 lines (37 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
typedef struct dados{
int dado;
struct dados *prox;
}Pilha;
Pilha *inserir(int valor,Pilha *pilha){
Pilha *novo = (Pilha *) malloc(sizeof(Pilha));
novo->dado = valor;
novo->prox = pilha;
return novo;
}
int main(){
FILE *file;
char arquivo[200];
Pilha *pilha = NULL;
int contador = 0;
printf("digite o nome do arquivo: ");
scanf("%s",arquivo);
file = fopen(arquivo,"r");
if(!file){
printf("arquivo nao abriu");
exit(0);
}
char numeros[100];
int valor;
while (fgets(numeros,100,file)!=NULL)
{
fscanf(file,"%d",&valor);
printf("%d\n",valor);
pilha = inserir(valor,pilha);
contador++;
}
printf("o ultimo valor inserido foi: %d\n",valor);
printf("%d",contador);
return 0;
}