Файл не удаляется с
Я попытался удалить содержимое файла ...но не deletetd
unsigned char buffer[64]; // buffer may be any size FILE *fp = fopen("image.pgm", "rb";); FILE *pFile; char *filename="text"; int ret; int numread; pFile=fopen(filename,"wb"); while (!feof(fp)) // repeat until reached end of file { int index; // index into the buffer numread = fread(buffer, sizeof(unsigned char), 64, fp); if (numread == 0) break; // no data left to read for (index = 0; index < numread; ++index) { // process each byte of the buffer char b = buffer[index]; // b contains the value of the current byte printf("byte %d: %c", index, b); fprintf(pFile,"%c",b); } fclose (pFile); ret = remove(filename); if(ret == 0) { printf("\n File deleted successfully"); } else { printf("\n Error: unable to delete the file"); } }
Что я уже пробовал:
unsigned char buffer[64]; // buffer may be any size FILE *fp = fopen(image.pgm,rb); FILE *pFile; char *filename="text"; int ret; int numread; pFile=fopen(filename,"wb"); while (!feof(fp)) // repeat until reached end of file { int index; // index into the buffer numread = fread(buffer, sizeof(unsigned char), 64, fp); if (numread == 0) break; // no data left to read for (index = 0; index < numread; ++index) { // process each byte of the buffer char b = buffer[index]; // b contains the value of the current byte printf("byte %d: %c", index, b); fprintf(pFile,"%c";,b); } fclose (pFile); ret = remove(filename); if(ret == 0) { printf("\n File deleted successfully"); } else { printf("\n Error: unable to delete the file"); }