Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. int main(){
  5. char *matriz;
  6. matriz = ( char * ) malloc ( 1000000 );//1 milhão de bytes ou 1MB
  7. int i;
  8. FILE *arq = fopen("Meuarquivo.txt", "r" );//113MB
  9. if ( arq == NULL ){
  10. textcolor(YELLOW);gotoxy(26,12);
  11. printf("Problemas na abertura do arquivo ");
  12. getche();
  13. return (0);
  14. }
  15. textcolor(WHITE);
  16. for ( i = 0; i < 64443; i++ ) {//Só lê e imprime até esta linha 64443.
  17. fgets ( matriz, 255, arq );
  18. printf("%d %s ", i, matriz );
  19. }
  20. //Tentei realocar mais memória más não adianta, a contagem
  21. //das linhas prossegue, más sai vazio, não imprime mais nada do arquivo
  22. //tentei resetar a matriz de várias forma, para preencher com dados
  23. //a partir da linha 64443 más também não resolveu.
  24. matriz = ( char * ) realloc ( matriz, 2000000 );//2 milhões de bytes ou 2MB
  25. textcolor(WHITE);
  26. for ( i = 64443; i < 128000; i++ ) {
  27. fgets ( matriz, 255, arq );
  28. printf("%d %s ", i, matriz );
  29. }
  30. fclose(arq);
  31. getche();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement