2) write a subroutine fstrcpy (char * s, char * t) to complete the function of the string handling function strcpy,
3) write a subroutine FSTRCMP (char * s, char * t) to complete the function of the string handling function STRCMP,
4) write a subroutine fstrlen (char * s) to complete the function of the string handling function strlen,
5) main function function: from the keyboard input string, call the above four sub-models function, output sub function return values or content change of string,
CodePudding user response:
Char * fstrcat (char * s, char * t)
{
int i=0;
Char * temp=s;
Char * temp2=t;
While (* temp!='\ 0')
{
i++;
Temp++;
}
While (* temp2)
{
S [i++]=* temp2;
Temp2 + +;
}
S [I]='\ 0';
return s;
}
CodePudding user response:
For your reference
# include & lt; stdio.h>
# include & lt; Stdlib. H>
//string concatenation
Char * fstrcat (char * s, char * t);
//string copy
Char * fstrcpy (char * s, char * t);
//string comparison
Int FSTRCMP (char * s, char * t);
//the length of the string
Int fstrlen (char * s);
Int main ()
{
Int j, k;
Char [100] s1 and s2 [100], s3 [100], s4 [100];
Char * p=s3.
Char * q=s4;
Printf (" \ n input the first string: ");
The scanf (" % s ", s1);
Printf (" \ n input the second string: ");
The scanf (" % s ", s2);
P=fstrcat (s1, s2);
Printf (" \ n after joining together string: % s \ n ", p);
Q=fstrcpy (s1 to s4);
Printf (" \ n \ n copy after string: % s ", q);
J=FSTRCMP (s1, s2);
If (j==1)
Printf (" [% s]] [% s \ n ", s1, s2);
Else if (j==0)
Printf (" [% s] with equal] [% s \ n ", s1, s2);
The else
Printf (" [% s] is smaller than] [% s \ n ", s1, s2);
K=fstrlen (s1);
Printf (" [% s] length is: % d \ n ", s1, k);
return 0;
}
//string concatenation
Char * fstrcat (char * s, char * t)
{
Int I=0, j=0;
While (s [I]!='\ 0')
{
i++;
}
J=I;
i=0;
While (t [I]!='\ 0')
{
S [j++] [i++]=t;
}
S [j]='\ 0';
return s;
}
//string copy
Char * fstrcpy (char * s, char * t)
{
int i=0;
While (s [I]!='\ 0')
{
T=s [I] [I];
i++;
}
T [I]='\ 0';
return t;
}
//string comparison
Int FSTRCMP (char * s, char * t)
{
int i=0;
While (s [I]!='\ 0' & amp; & T [I]!='\ 0')
{
If (s [I] & gt; [I] t)
return 1;
Else if (s==[I] t [I])
return 0;
The else
return -1;
i++;
}
}
//the length of the string
Int fstrlen (char * s)
{
int i=0;
While (s [I]!='\ 0')
{
i++;
}
return i;
}