GeekInterview.com
Series: Subject: Topic:
Question: 36 of 238

String Concatination

How to concatenate the two string without using the predefined functions (such as strcat and strlen)?
Asked by: Tarkeshwar_Prasad | Member Since Feb-2009 | Asked on: Mar 15th, 2009

View all questions by Tarkeshwar_Prasad   View all answers by Tarkeshwar_Prasad

Showing Answers 1 - 3 of 3 Answers
kakiharanadh

Answered On : Apr 13th, 2009

View all answers by kakiharanadh

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;
}

  
Login to rate this answer.
vbablu

Answered On : Jul 2nd, 2009

View all answers by vbablu

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);
                  }

  
Login to rate this answer.
vbablu

Answered On : Jul 2nd, 2009

View all answers by vbablu

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");
}

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.