String Concatination

How to concatenate the two string without using the predefined functions (such as strcat and strlen)?

Questions by Tarkeshwar_Prasad   answers by Tarkeshwar_Prasad

Showing Answers 1 - 3 of 3 Answers

char* strcat(char *s, char*t)
{
    if( t == NULL)
      return s;

      char *temp =s;
      while( *s != '')  // don't compare like *s++!='' it lead to errors since wrong pointing.
       s++;
      while( (*s++ = *t++)!='');
      return temp;
}

  Was this answer useful?  Yes

vbablu

  • Jul 2nd, 2009
 

void main() { char s1[40],s2[20]; int i=0,j=0;
                      printf("enter a string");
                     scanf("%s",s1);
                     printf("enter another string");
                     scanf("%s",s2);
                      while(s1[i]!='')
                        i++;
                      while(s2[j]!='')
                       s1[i++]=s2[j++];
                       s1[i]='';
                      printf("concatenated string is%s",s1);
                  }

  Was this answer useful?  Yes

vbablu

  • Jul 2nd, 2009
 

void main() { char s[20]; int i,n;
????????????????????????????? printf("enter a string");
??????????????????????????????? scanf("%s",s);
????????????????????????????? for(i=0;s[i]!='';i++)
?????????????????????????????? {
??????????????????????????????????????????? if(s[i]=='.')
???????????????????????????????????????? {
??????????????????????????????????????? s[i]='';
???????????????????????????????????????????? break;
????????????????????????????????????? }}
??????????????????????????????? n=atoi(s);
??????????????????????????? if(n<255)
??????????????????????????? printf("%d is less");
?????????????????????????? else
??????????????????? printf("not less");
?????????????????? }
??

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions