zephirus Posted November 10, 2009 at 05:56 PM Report Share #295466 Posted November 10, 2009 at 05:56 PM Boas, Sou bastante noob nestas questões do C++. Peço desde já desculpa se a pergunta não fizer sentido mas gostava de saber como ler um ficheiro binário muito grande (formato double), e conseguir fazer o seu display. Testei este código mas obtenho apenas zeros: FILE * pFile; long lSize; double * buffer; size_t result; pFile = fopen("data.bin" ,"rb"); if (pFile==NULL) {fputs ("File error",stderr); exit (1);} //obtain file size: fseek (pFile , 0 , SEEK_END); lSize = ftell (pFile); rewind (pFile); /*allocate memory to contain the whole file:*/ buffer = (double*) malloc (sizeof(double)*lSize); if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);} int i,rc; for (i = 0; (rc = getc(pFile)) != EOF && i < 5; buffer[i++] = rc); fclose(pFile); if (i == 5) { puts("The bytes read were..."); printf("%x %x %x %x %x\n", buffer[1000], buffer[1], buffer[2], buffer[340], buffer[4]); } else fputs("There was an error reading the file.\n", stderr); return EXIT_SUCCESS; Link to comment Share on other sites More sharing options...
Baderous Posted November 10, 2009 at 07:39 PM Report Share #295480 Posted November 10, 2009 at 07:39 PM Já reparaste nos warnings que dá? teste.c: In function ‘main’:teste.c:30: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘double’ teste.c:30: warning: format ‘%x’ expects type ‘unsigned int’, but argument 3 has type ‘double’ teste.c:30: warning: format ‘%x’ expects type ‘unsigned int’, but argument 4 has type ‘double’ teste.c:30: warning: format ‘%x’ expects type ‘unsigned int’, but argument 5 has type ‘double’ teste.c:30: warning: format ‘%x’ expects type ‘unsigned int’, but argument 6 has type ‘double’ teste.c:9: warning: unused variable ‘result’ Depois estás ali a aceder ao buffer[1000] e buffer[340] quando só estás a colocar no buffer informação até ao índice 4 inclusivé. Por último, isto de C++ tem pouco. Link to comment Share on other sites More sharing options...
zephirus Posted November 10, 2009 at 09:45 PM Author Report Share #295496 Posted November 10, 2009 at 09:45 PM Podes indicar-me algum sitio em que tenha um exemplo daquilo que pretendo fazer? Obrigado Link to comment Share on other sites More sharing options...
Quadrado Posted November 11, 2009 at 03:33 PM Report Share #295586 Posted November 11, 2009 at 03:33 PM é impressão minha ou aquilo é mais c do que c++? lolololololol 🙂 Será? Porquê? O quê? - Estudar Sempre - Link to comment Share on other sites More sharing options...
zephirus Posted November 11, 2009 at 03:35 PM Author Report Share #295587 Posted November 11, 2009 at 03:35 PM é impressão minha ou aquilo é mais c do que c++? lolololololol 🙂 Bom, isso não ajuda nada. Eu disse no meu post que não estava muito dentro disto, aliás, esta questão foi-me pedida por uma pessoa que não podia no momento colocá-la aqui. Se alguém puder ajudar, óptimo, se for para fazer comentários vazios, escusam de escrever. Link to comment Share on other sites More sharing options...
Quadrado Posted November 11, 2009 at 03:38 PM Report Share #295588 Posted November 11, 2009 at 03:38 PM eu de c++ tambem não sei muito...lolololol Será? Porquê? O quê? - Estudar Sempre - Link to comment Share on other sites More sharing options...
zephirus Posted November 11, 2009 at 03:41 PM Author Report Share #295589 Posted November 11, 2009 at 03:41 PM eu de c++ tambem não sei muito...lolololol Então porque é que vens para aqui mandar esses comentários. Não era melhor estares quieto? Link to comment Share on other sites More sharing options...
Quadrado Posted November 11, 2009 at 03:50 PM Report Share #295592 Posted November 11, 2009 at 03:50 PM vim aqui para oferecer os meus préstimos se precisares de trabalhar só em cC, não foi por mal... 🙂 Será? Porquê? O quê? - Estudar Sempre - Link to comment Share on other sites More sharing options...
Quadrado Posted November 11, 2009 at 03:50 PM Report Share #295594 Posted November 11, 2009 at 03:50 PM por isso é que disse que parecia mais C que C++... Será? Porquê? O quê? - Estudar Sempre - Link to comment Share on other sites More sharing options...
zephirus Posted November 11, 2009 at 03:56 PM Author Report Share #295597 Posted November 11, 2009 at 03:56 PM vim aqui para oferecer os meus préstimos se precisares de trabalhar só em cC, não foi por mal... 🙂 Tem de ser em C++. Obrigado de qualquer forma. Link to comment Share on other sites More sharing options...
Quadrado Posted November 11, 2009 at 03:58 PM Report Share #295598 Posted November 11, 2009 at 03:58 PM De nd se precisares em C, ja sabes não hesites em contactar. ? Será? Porquê? O quê? - Estudar Sempre - Link to comment Share on other sites More sharing options...
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