Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to delete a file in C

2 Answers

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
     
int main(int argc, char **argv) 
{ 
    //  int unlink(const char *pathname) deletes a name from the filesystem
     
    if (unlink("d:\\data.bin") == -1) {
        puts("Error delete file");
        exit(1);
    }
 
    puts("File deleted");
      
    return 0;
}
     
     
     
     
/*
    
run:
     
File deleted
  
*/

 



answered Aug 13, 2015 by avibootz
edited Apr 13, 2024 by avibootz
0 votes
#include <stdio.h>
 
int main() {
    char file[100] = "d:\\data.txt";
 
    int del = remove(file); // int remove(const char *filename) deletes the given filename
     
    if (!del) {
        printf("File Deleted successfully\n");
    }
    else {
        printf("Delete error\n");
    }
     
    return 0;
}
  
  
       
/*
run:
    
File Deleted successfully    
 
*/

 



answered Apr 13, 2024 by avibootz

Related questions

2 answers 220 views
2 answers 258 views
1 answer 162 views
162 views asked Jun 8, 2018 by avibootz
1 answer 81 views
81 views asked Jul 27, 2023 by avibootz
1 answer 105 views
105 views asked Jun 19, 2020 by avibootz
...