Hola, amigos, estoy haciendo pequeños experimentos, y necesito leer un archivo.
Resulta que el codigo lo que hace es cargar el archivo en una memoria dinamica a traves de un puntero, pero al usar fread capta algo como "COM;<" al final del archivo, cosa que no es verdad.
No sé de donde aparece, pero les dejo el codigo, por si pueden ayudar, gracias.
///This program receives a list of files in a text file, and glue togheter with a plus:
///all are compressed. The program can extract one file if the user wants it. The package
///can not be modified.
#include <stdio.h>
#include <stdlib.h>
struct package_header{
int magic_number; //0xDEADBEFF;
int number_of_files_stored;
};
struct file_entry{
char file_name[64];
int file_start;
int file_size;
};
int main(int argc, char *argv[])
{
if(argc < 2){
printf("Usage: mesa-pack.exe <list of files to package.txt>\n"); }
FILE *list_of_files;
FILE *package;
int filesize;
char *content;
char *token;
list_of_files
= fopen(argv
[1], "rb"); if(list_of_files == NULL){
printf("File list is damaged or computer unexpected error while opening file. Try again.\n"); return -1;
}
fseek(list_of_files
, 0, SEEK_END
); filesize
= ftell(list_of_files
); fseek(list_of_files
, 0, SEEK_SET
);
content
= (char *)calloc(filesize
, sizeof(char));
//memset(content, 0, filesize);
fread((char *) content
, filesize
, 1, list_of_files
);
printf("filesize = %d\n", filesize
); printf("File content: %s\n", content
);
printf("Showing list of files to package...\n\n"); token
= strtok(content
, "\n"); while(token != NULL){
printf("token = %s\n", token
);
}
return 0;
}
http://subefotos.com/ver/?dba9f455a39df69e79173249a0764a0fo.jpg