#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char filename[80];
FILE *pfile = fopen("packet.txt","a");
while (true)
{
scanf("%s", filename);
if (strcmp(filename,"exit") == 0) break;
FILE *checkfile = fopen(filename,"r");
if (!checkfile)
{
printf("file not found\n");
continue;
}
fputs("\nfilename ",pfile);
fwrite(filename,sizeof(char), strlen(filename), pfile);
FILE *pFile = fopen (filename,"rb");
fseek (pFile, 0, SEEK_END);
int filesize = ftell (pFile);
fseek (pFile, 0, SEEK_SET);
char *buffer =(char*) malloc (filesize);
fread(buffer,1,filesize,pFile);
buffer[filesize] = 0;
fputs("\n", pfile);
fputs(buffer, pfile);
fputs("\n", pfile);
fputs("endfile", pfile);
fclose(checkfile);
fclose(pFile);
}
}
|