I am trying to delete a file in c program. Assume that the file is located in current directory of source file. I have searched a lot but didn't get any solution. Everyone is suggesting to use remove() function.
Here is my source code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
int delete_status;
char del[50];
printf("Enter a file name to delete it: ");
gets(del);
delete_status = remove(del);
if(delete_status!=0) {
printf("File can not be deleted!\nFile does not exist in current directory\n");
}
else printf("File %s has been deleted successfully!\n", del);
return 0;
}
Is there any way to remove file without using remove() function. I want to code manually without using any other stl built in function.
gets()compounds the problems. If the size was 4096, you'd be better off, but still vulnerable. You cannot usegets()safely, full stop. Also note that STL is normally associated with C++ and not with C. And it isn't clear what you mean by 'any other STL built in function'. System calls are not built in within the normal meaning of the term.remove()is Standard C. What is wrong with it?