Write a program that. given two strings, append the second string to the first
Sample Questions and answers
#include <stdio.h>
main()
{
int n=0;
char *ptr=”pointer”;
puts(“Enter the string”);
gets(ptr);
fflush(stdin);
for(;*ptr!=’’;ptr++)
n++;
printf(“
The length of the string is %d”, n);
}
#include <stdio.h>
main(){
char *str1="string one";
char *str2 ="string two";
puts ("
Enter first string"):
gets (str1) ;
fflush(stdin) ;
puts ("
Enter second string");
gets (str2) ;
fflush (stdin);
for(;*str1==*str2 && (*str1! ='’ || *str2!=’); str1++, str2++) ;
if(*str1==’ ’ && *str2==''){
printf(“
The strings are equal”);
return;
}
if (*str1> *str2)
printf(“
The first string is bigger than the second”);
else
printf(“
The second string is bigger than the first”);
return;
}
#include <stdio.h>
main(){
char *string1= "string one";
char *string2 ="string two";
puts ( "
Enter the string");
gets (string2);
fflush (stdin) ;
while (*string2!=’'){
*string1=*string2 ;
String1++;
}
*string1= '’ ;
printf("
The copy is over”);
return;
}
#include <stdio.h>
main(){
char *string1="string one”;
char *string2 ="string two";
puts ("
Enter first string");
gets (string1) ;
fflush(stdin);
puts ("
Enter second string”);
gets (string2);
fflush(stdin);
for(;*string1 != ‘’;string1++); /* traverse to the end of string1 */
while (*string2! = ‘’){
*string1=*string2;
string1++;
string2++;
}
*string1 = ‘’;
return;
}