抱歉没看清楚 
其实是在S1E22的课后作业有一题一直没办法实现,才到处尝试是不是有什么地方是代码本身就出问题的。
实现strcpy函数的:
不知哪里出错
#include<stdio.h>
#define Max 100
int main()
{
char a[(Max+4)];
char b[Max];
int n;
printf("I'll demonstrate the strcmp function.\nEnter the first sentence.\n:");
fgets(a,Max,stdin);
printf("Enter the second sentence that u want to be compared with the previous one.\n");
fgets(b,Max,stdin);
printf("Now, enter the total number of charactor u want to compare with.");
scanf("%d",&n);
n=strcmp_n(a,b,n);
if (n>0)
{
printf("%d",n);
if (n-1>0) printf("\nWhich is right after %s",(a+100));
}
else printf("Former %d words are equal.",(-n));
return 0;
}
int strcmp_n(char* i,char* j,int k)
{
int m=1;
while ((*i==*j++)&& k--&& *i)
{
if (*i++<0)
{
if (*i!=*j) goto ret;
if (*(i+1)!=*(j+1)) goto ret;
i+=2;
j+=2;
}
m++;
}
if (k==-1||*i == 0) return (1-m);
ret: j-=2;
if (*j<0)
{
j-=2;
*(i+100)=*j++;
*(i+101)=*j++;
*(i+102)=*j;
*(i+103)='\0';
}
else
{
*(i+100)=*j;
*(i+101)='\0';
}
return m;
}
|