一道关于文件的面试题
【摘要】 /*设有文件a.file, 请写出程序在文件的开头插入 字符串 “ file start: ”;*/ #include <stdio.h>#include <stdlib.h>#include <string.h> int main(){ int len; char ch; char str[1024] = "file start:";...
-
/*设有文件a.file, 请写出程序在文件的开头插入 字符串 “ file start: ”;
-
*/
-
-
-
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
-
int main()
-
{
-
int len;
-
char ch;
-
char str[1024] = "file start:";
-
FILE *fp;
-
-
len = strlen(str);
-
-
fp = fopen("a.file","r+");
-
if (fp == NULL)
-
{
-
printf("打开文件失败!\n");
-
exit(0);
-
}
-
-
while((ch = getc(fp)) != EOF)
-
{
-
str[len] = ch;
-
len++;
-
}
-
if (!fseek(fp,0,SEEK_SET))
-
{
-
for (len = 0; len<(int)strlen(str); len++)
-
{
-
fputc(str[len],fp);
-
}
-
}
-
fclose(fp);
-
return 0;
-
}
文章来源: blog.csdn.net,作者:悦来客栈的老板,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq523176585/article/details/12653001
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)