Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
JoaoNascimento

erro ao ler ficheiro

Recommended Posts

JoaoNascimento

Ola...

Tnh o seguinte codigo para ler um ficheiro, mas nao compilar aparecem valores estupidos e o compilador para de funcionar...

void ler_dados_fich(char *curso[N][50],char *nomeuc[N][50],char *area_cientifica[N][50], int *ects[N], int *opcional[N],char *doc_res[N][50],char *docentes[N][50],int *ano[N],int *semestre[N],int *turm_t[N],int *turm_tp[N],int *turm_p[N],int *turm_pl[N],int *turm_ac[N],int *turm_ot[N],int *turm_s[N],int *t[N],int *p[N],int *tp[N],int *pl[N],int *ac[N],int *ot[N],int *s[N])
{
char cabecalho[500];
int i;
FILE *pfdados;
pfdados=fopen("dados_ucs_070410.txt","r");

if(pfdados==NULL)
{
	printf("Erro ao abrir o ficheiro! \n");
	system("pause");
}

fscanf(pfdados,"[^\n]\n",&cabecalho);
printf("%s\n",cabecalho);
for (i=0;i<92;i++)
{
	fscanf(pfdados,"%[^\t]\t%d\t%d\t%[^\t]\t%d\t%[^\t]\t%d\t%[^\t]\t%[^\t]\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t",curso[i],&ano[i],&semestre[i],nomeuc[i],&ects[i],area_cientifica[i],&opcional[i],doc_res[i],docentes[i],&turm_t[i],&turm_tp[i],&turm_p[i],&turm_pl[i],&turm_ac[i],&turm_ot[i],&turm_s[i],&t[i],&tp[i],&p[i],&pl[i],&ac[i],&ot[i],&s[i]);
	printf("%s\t%d\t%d\t%s\t%d\t%s\t%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t",curso[i],ano[i],semestre[i],nomeuc[i],ects[i],area_cientifica[i],opcional[i],doc_res[i],docentes[i],turm_t[i],turm_tp[i],turm_p[i],turm_pl[i],turm_ac[i],turm_ot[i],turm_s[i],t[i],tp[i],p[i],pl[i],ac[i],ot[i],s[i]);
}
}

Share this post


Link to post
Share on other sites
Localhost

Começam a aparecer valores estúpidos e o compilador deixa de funcionar? :bored:


here since 2009

Share this post


Link to post
Share on other sites
martinhocosta

usa isto

FILE *p;

                p = fopen("dados_ucs_070410.txt","r");

                while (!feof(p))

                {

                  d = getc(p);

                  printf("%c",d);

                }

                fclose(p);

                system("pause");

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.