T_E Posted December 4, 2006 at 07:56 PM Report #68765 Posted December 4, 2006 at 07:56 PM é assim eu fiz este programa para ler de um ficheiro chamado netlist1.txt. e queria saber se alguém me pode ajudar porque isto não esta a funcionar. o programa é o seguinte: #include <stdio.h> #include <stdlib.h> #include <conio.h> main() { FILE *fp; char componente,referencia; int no1,no2,valor1,valor2; /* abre o ficheiro dados.txt para leitura e as */ fp = fopen( "netlist1.txt", "r" ); if( fp == NULL ) { printf("ERRO: não consigo abrir o ficheiro netlist.txt\n"); exit(1); } /* leitura e escrita */ while(fscanf( fp, "%c %c %d %d %d %d",&componente,&referencia,&no1,&no2,&valor1,&valor2)!=EOF); printf("%c %c %d %d %d %d",componente,referencia,no1,no2,valor1,valor2); /* fecha os ficheiros */ fclose( fp ); } e o que tinha de aparecer era o seguinte: UR s 1 0 15 1000 R a 1 2 2200 R b 1 3 1500 R c 2 3 4700 R d 2 0 560 R e 3 0 3300 se alguem me pudesse ajudar agradecia mt..
Rui Carlos Posted December 4, 2006 at 07:59 PM Report #68766 Posted December 4, 2006 at 07:59 PM no 'fscanf' não falta um '\n' no fim? EDIT: e já agora no printf também... Rui Carlos Gonçalves
Warrior Posted December 4, 2006 at 08:47 PM Report #68789 Posted December 4, 2006 at 08:47 PM no scanf é negligenciável, no printf melhora a apresentação. while(fscanf( fp, "%c %c %d %d %d %d",&componente,&referencia,&no1,&no2,&valor1,&valor2)!=EOF); Remover o ; do final do while deve resolver
Saco Posted December 4, 2006 at 09:36 PM Report #68799 Posted December 4, 2006 at 09:36 PM Atenção que logo na primeira linha tens UR, se lês um %c só apanhas o U...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now