Results 1 to 2 of 2
This is a strcat code I wrote,has a problem,please help me,please.Thanks
Code:
#include<stdio.h>
#include<assert.h>
char *mystrcat(char *dest,char *src)
{
assert(dest!=NULL&&src!=NULL);
dest+=strlen(dest);
while(*dest++==*src++);
return dest;
}
main()
{
char str[50]="hello,world";
char ...
- 05-06-2010 #1Just Joined!
- Join Date
- May 2010
- Posts
- 2
My strcat's problem
This is a strcat code I wrote,has a problem,please help me,please.Thanks
Code:#include<stdio.h> #include<assert.h> char *mystrcat(char *dest,char *src) { assert(dest!=NULL&&src!=NULL); dest+=strlen(dest); while(*dest++==*src++); return dest; } main() { char str[50]="hello,world"; char str2[10]="world"; printf("%s\n",mystrcat(str,str2)); }
- 05-06-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Is this a class exercise/problem? In any case, you don't specify what the problem is. In any case, you have at least one problem:
You are comparing, not assigning the contents of src to dest.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote