一道二级考试的难题,求解函数部分的意思
#include<stdio.h>#include<string.h>
int Replace_string(char line[],char str1[],char str2[])
{
int i=0,j,loc;
char temp[80];
while(i<=strlen(line)-strlen(str2))
{
j=0;
loc=i;
while(str1[j]==line[loc]&&str1[j]!='\0')
{
loc++;
j++;
}
if(str1[j]=='\0')
{
strcpy(temp,&line[loc]);
strcpy(&line[i],str2);
i+=strlen(str2);
strcpy(&line[i],temp);
return 1;
}
else i++;
}
return 0;
}
main()
{
FILE *fp;
char string[100]="My EXAM_number is 0112404321";
char number[11]="0112404321",num[11];
fp=fopen("myf2.out","w");
if(fp==NULL)
{
printf("Can not open the file!\n");
exit(0);
}
fprintf(fp,"%s\n",string);
gets(num);
Replace_string(string,number,num);
fprintf(fp,"%s\n",string);
fprintf(fp,"\nmy exam number is:%s","0112400123");
fclose(fp);
}
[[it] 本帖最后由 空心人 于 2009-8-4 19:25 编辑 [/it]]