亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將以下兩個函數通過一個主函數調用,求調用后的程序

將以下兩個函數通過一個主函數調用,求調用后的程序

C PHP
斯蒂芬大帝 2023-03-05 18:14:31
文件的分割#include<stdio.h>int main(){int len=0;int len2=0;FILE* stream;FILE* stream1;FILE* stream2;char buf[50];char buf1[50];char buf2[50];char text[1024];printf("input anfile path to open:");scanf("%s",buf);stream=fopen(buf,"r+");fseek(stream,0,SEEK_END);len=ftell(stream);printf("the file %s length is %d!\n",buf,len);len2 = len/2;printf("intput 2 file name: \n");scanf("%s%s",buf1,buf2);fseek(stream,0,SEEK_SET);stream1=fopen(buf1,"w+");stream2=fopen(buf2,"w+");fread(text,len2,1,stream);fwrite(text,len2,1,stream1);fread(text,len-len2,1,stream);fwrite(text,len-len2,1,stream2);fclose(stream);fclose(stream1);fclose(stream2);return 0;} 文件的合并#include<stdio.h>int main(){int len=0;int len2=0;FILE* stream;FILE* stream1;char buf[50];char buf1[50];char text[1024];printf("input anfile path to open:");scanf("%s",buf);stream=fopen(buf,"r+");fseek(stream,0,SEEK_END);printf("intput another file name: \n");scanf("%s",buf1);stream1=fopen(buf1,"r+");fseek(stream1,0,SEEK_END);len=ftell(stream1);fseek(stream1,0,SEEK_SET);fread(text,len,1,stream1);fwrite(text,len,1,stream);fclose(stream);fclose(stream1);remove(buf1);//remove the another filereturn 0;}
查看完整描述

2 回答

?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

首先,c中有且僅有一個主函數,所以第一步,你必須的把兩個函數改成其他名字:
#include <stdio.h>

int function1()
{
int len=0;
int len2=0;
FILE* stream;
FILE* stream1;
FILE* stream2;
char buf[50];
char buf1[50];
char buf2[50];
char text[1024];

printf("input anfile path to open:");

scanf("%s",buf);
stream=fopen(buf,"r+");

fseek(stream,0,SEEK_END);
len=ftell(stream);
printf("the file %s length is %d!\n",buf,len);
len2 = len/2;

printf("intput 2 file name: \n");
scanf("%s%s",buf1,buf2);
fseek(stream,0,SEEK_SET);
stream1=fopen(buf1,"w+");
stream2=fopen(buf2,"w+");
fread(text,len2,1,stream);
fwrite(text,len2,1,stream1);
fread(text,len-len2,1,stream);
fwrite(text,len-len2,1,stream2);

fclose(stream);
fclose(stream1);
fclose(stream2);

return 0;

int function2()
{
int len=0;
int len2=0;
FILE* stream;
FILE* stream1;

char buf[50];
char buf1[50];

char text[1024];

printf("input anfile path to open:");

scanf("%s",buf);
stream=fopen(buf,"r+");

fseek(stream,0,SEEK_END);

printf("intput another file name: \n");
scanf("%s",buf1);

stream1=fopen(buf1,"r+");
fseek(stream1,0,SEEK_END);
len=ftell(stream1);
fseek(stream1,0,SEEK_SET);
fread(text,len,1,stream1);
fwrite(text,len,1,stream);

fclose(stream);
fclose(stream1);
remove(buf1);//remove the another file

return 0;
}

//第二部:如果有條件的調用它們的話,加上if語句或者switch語句,基本上都是這樣,此外,你可以把function1 和function2放入一個頭文件中,然后包含這個頭文件亦行。
void main()
{

function1();
function2();
}

 


查看完整回答
反對 回復 2023-03-08
?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

不知道你的具體要求是什么,如果想從主函數調用這兩個函數,把這兩個函數名改完就可以了
#include<stdio.h>
//文件的分裂
int SplitFile ()//修改的地方
{
。。。。。 } 
文件的合并
#include<stdio.h>

int ConveFile()//修改的地方
{。。。
}
void main()
{
//如果是有條件的選擇這兩個函數的話,也可以加一些if語句
SplitFile();
ConveFile();
}


查看完整回答
反對 回復 2023-03-08
  • 2 回答
  • 0 關注
  • 115 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號