如何清空结构体数组?

如何清空结构体数组?,第1张

你想清空?那就是全部置0哦,比如stru_data是一个结构体,可以这样:memset(&stru_data,0,sizeof(stru_data))ps:stru_data是一个对象,如果是指针指向的话,上面就不用&,后面就是sizeof(/*里面是结构体的名字*/)

1、使用重定向的方法

[root@centos7 ~]# du -h test.txt

4.0Ktest.txt

[root@centos7 ~]# >test.txt

2、使用true命令重定向清空文件

[root@centos7 ~]# du -h test.txt

4.0Ktest.txt

[root@centos7 ~]# true >test.txt

[root@centos7 ~]# du -h test.txt

0test.txt

3、使用cat/cp/dd命令及/dev/null设备来清空文件

[root@centos7 ~]# du -h test.txt

4.0Ktest.txt

[root@centos7 ~]# cat /dev/null > test.txt

[root@centos7 ~]# echo "Hello World" >test.txt

[root@centos7 ~]# du -h test.txt

4.0Ktest.txt

[root@centos7 ~]# cp /dev/null test.txt

cp:是否覆盖"test.txt"? y

[root@centos7 ~]# echo "Hello World" >test.txt

[root@centos7 ~]# dd if=/dev/null of=test.txt

4、使用echo命令清空文件

[root@centos7 ~]# echo "Hello World" >test.

[root@centos7 ~]# echo -n "" >test.txt==>要加上"-n"参数,默认情况下会"\n",也就是回车符

5、使用truncate命令清空文件

[root@centos7 ~]# du -h test.txt

4.0Ktest.txt

[root@centos7 ~]# truncate -s 0 test.txt -s参数用来设定文件的大小,清空文件,就设定为0;


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7661248.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-08
下一篇2023-04-08

发表评论

登录后才能评论

评论列表(0条)

    保存