How do I clear the whole contents of a file in C?

前端 未结 5 1109
闹比i
闹比i 2020-12-09 02:51

I have a file with some of user1\'s data. I want to use the same file for user2 by clearing the content of the file.

My idea is that when a new user comes, data of

5条回答
  •  天涯浪人
    2020-12-09 03:45

    There are two ways:

    1. fd=open(filename,O_RDONLY | O_WRONLY | O_TRUNC);
    
    
    2. [cat /dev/null > filename] for BASH. It can be directly used in c program using [system()] system call. 
    
       system("cat /dev/null > filename");   
    

提交回复
热议问题