Find the answer to your Linux question:
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 ...
  1. #1
    Just 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));
    }

  2. #2
    Linux Guru Rubberman's Avatar
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...