c語言文件分割
㈠ 求c語言編程文件的分割與合並源代碼與程序框圖(課程設計)
c語言的把一個文件分成相等的兩個文件。
#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 file
return 0;
 }
需要在程序目錄下有文件存在
㈡ C語言文件分割問題
舉個例子,502位元組的文件分成5個子文件,前四個(i!=n)都是100位元組(用d<=ev_sizef判斷),第五個有102位元組,就不能用<100判斷了,而是利用fread的返回值判斷只要讀取到就輸出
,
㈢ C語言如何將文件中一行內容按照空格分割,並將每個單詞寫入數組
程序已調試過,運行的時候把filename改為你自己路徑下的文件。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char str[1000];
void  openfile(char *filename)
{
	FILE *fp;
	int file_size;
	if((fp=fopen(filename,"r")) == NULL)
	{
		printf("can not open this file\n");
		exit(0);
	}
	fseek(fp,0,SEEK_END);
	file_size=ftell(fp);
	printf("%d\n",file_size);
	fseek(fp,0,SEEK_SET);
	fread(str,sizeof(char),file_size,fp);
	str[file_size-1]='\0';
	printf("%s\n",str);
	fclose(fp);
}
void Split()
{
	char w[100][100];
	char *pfirst=str;
	char *pend;
	int i=0;
	int j,sum=0;
	memset(w,0,sizeof(w));
	while(pfirst)
	{
		pend=strstr(pfirst," ");
		if(pend==NULL)
		{
			strncpy(w[i],pfirst,strlen(str)-sum);
			i++;
			break;
		}
		strncpy(w[i],pfirst,pend-pfirst);
		sum+=pend-pfirst+1;
		pfirst=++pend;
		i++;
	}
	for(j=0;j<i;j++)
		printf("%s ",w[j]);
	
}
int main()
{
	char filename[40]="/opt/opthb/liuly/a.txt";
	openfile(filename);
	Split();
	return 0;
}
㈣ 如何把一個復雜的C語言源代碼分成幾個文件,然後在dev c++上進行多文件編譯
假設我們要更改的源代碼如下:

即「No such file or directory」就是沒有文件或者路徑。說明你的路徑寫錯了,在編程時務必要注意一下。
㈤ C語言實現文本分割 有一個文本文件裡面用很多信息用換行分割,我要把每個信息單獨提取出來該怎麼辦
charszBuff[512]={0};//前提是要知道每行最長長度
fgets(szBuff,sizeof(szBuff),m_pFile));//m_pFile是打開文件的句柄。fgets讀取一行內容,再加個循環直到文件結尾
㈥ C語言如何實現文件分割功能
strcat()是追加字元串的函數。
strcat(char[] a,char []b)即將第二個字元串追加到第一個字元串末尾,第二個字元串值不變,第一個變長。
你的理解是對的 但是使用有誤!追加時需要保證第一個字元串在加上第二個之後依舊不能溢出。在此題中,你的a[]字元串長度在追加上".txt"之後,會溢出,建議在定義a的時候寫上char a[100]保證不溢出。
㈦ C語言分割字元串
使用strtok函數即可實現分割字元串。
1、strtok函數:
原型:char *strtok(char s[], const char *delim);
功能:將一個字元串分解為一組字元串,s為要分解的字元串,delim為分隔符字元串;
說明:當strtok函數在參數s的字元串中發現參數delim中包含的分割字元時,則會將該字元改為  字元。在第一次調用時,strtok()必需給予參數s字元串,往後的調用則將參數s設置成NULL。每次調用成功則返回指向被分割出片段的指針;
頭文件:string.h;
返回值:從字元串s開頭開始的一個個被分割的字元串。分割結束時,返回NULL。所有delim中包含的字元都會被濾掉,並將被濾掉的地方設為一處分割的節點。
2、常式:
#include<stdio.h>
#include<string.h>
intmain(){
charinput[16]="abc,d,ef,g";//待分解字元串
char*delim=",";//分隔符字元串
char*p=strtok(input,delim);//第一次調用strtok
while(p!=NULL){//當返回值不為NULL時,繼續循環
printf("%s ",p);//輸出分解的字元串
p=strtok(NULL,delim);//繼續調用strtok,分解剩下的字元串
}
return0;
}
㈧ C語言文件分割合並
文件是你分割的,想合並有什麼難題呢?
順次讀取原分割好的多個文件,寫入到一個文件就可以了。
我們可以看看winrar文件是如何分割文件的。分割後的每個文件文件名有規律,從01開始編號。順次讀取指定文件夾中的文件,如果文件不存在了,說明讀入結束了。
