FILE *fp;
if(!(fp=fopen(filename,"rb")))
{
printf("Cannot open '%s' for reading. Exit.\n",filename);
exit(1);
}
/* get file size */
fseek (fp, 0, SEEK_END);
filesize = ftell(fp);
fseek (fp, 0, SEEK_SET);
/* read file in buf */
buf = (unsigned char *) malloc(filesize+1);
if(!buf)
{
printf("Cannot allocate %lu bytes. Exit.\n",filesize);
exit(1);
}
unsigned long int readed=fread(buf,1,filesize,fp);
if(readed!=filesize)
{
printf("By some reason i cant read '%s'. I want to read %lu bytes, but can read only %lu bytes.Exit.\n", filename, filesize, readed);
exit(1);
}
fclose(fp);
if(debug)printf("File read complete\n");
我不会C++,但是看代码,这段代码是将一个文件读到内存。如果用autoit重现这个过程呢?
我用fileread和_FileReadToArray,结果都不对。
大家帮忙看看。 |