A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
remove deletes a file from the filesystem. On POSIX systems it also removes empty directories (it is equivalent to unlink for files and rmdir for directories). It returns 0 on success and -1 on failure, setting errno to indicate why. The file must not be open by your process on some platforms. On Windows, attempting to remove an open file fails with a sharing violation.
#include <stdio.h>#include <errno.h>#include <string.h>int main(void) {FILE *fp = fopen("temp_delete_me.txt", "w");if (fp) {fputs("temporary data\n", fp);fclose(fp);}int result = remove("temp_delete_me.txt");if (result == 0) {printf("File deleted successfully.\n");} else {printf("Failed to delete: %s\n", strerror(errno));}result = remove("nonexistent_file.txt");if (result != 0) {printf("Expected failure: %s\n", strerror(errno));}return 0;}
strerror(errno) converts the error code into a human-readable string. This is the standard pattern for reporting system call failures in C. You will see it throughout the system interaction and file I/O modules. The errno variable is thread-local in modern implementations, so concurrent threads do not clobber each other's error codes.
remove is the C standard library's file deletion function. For more control on POSIX systems, unlink and rmdir give you separate semantics. On Windows, _unlink and _rmdir are the platform equivalents. Next: rename, for moving and renaming files atomically.
Finish the lesson once you have worked through the material. This awards ★ 20 XP.