Jump to content

[C] Ajuda: Problemas com o código


Recommended Posts

Posted

é 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..

Posted

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

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
×
×
  • Create New...

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.