CONCATENATION OF TWO STRINGS USING POINTER IN C PROGRAM






Concatenation of two strings using pointer in c programming language


#include<stdio.h>
int main(){
  int i=0,j=0;
  char *str1,*str2,*str3;
  puts("Enter first string");
  gets(str1);
  puts("Enter second string");
  gets(str2);
  printf("Before concatenation the strings are\n");
  puts(str1);
  puts(str2);
  while(*str1){
      str3[i++]=*str1++;
  }
  while(*str2){
      str3[i++]=*str2++;
  }
  str3[i]='\0';
  printf("After concatenation the strings are\n");
  puts(str3);
  return 0;
}





3. Write a c program to delete the all consonants from given string.

15 comments:

Anonymous said...

this has helped me a lot....
n i found dis rily useful....

Anonymous said...

realy very much useful thank you

Anonymous said...

great program..thanks..

Anonymous said...

a great effort. helped me a lot in my assignment. thanks.

Anonymous said...

simply awesome and dam helpful

sa said...

i got segmentation fault... why?

Priyanka kumari said...

Hi sa,

I think you are not using Turbo C compiler.
Code for all types of compilers

//CONCATENATION OF TWO STRINGS IN C PROGRAM

#include
int main(){
int i=0,j=0;
char str1[100],str2[100],str3[100];
puts("Enter first string");
gets(str1);
puts("Enter second string");
gets(str2);
printf("Before concatenation the strings are\n");
puts(str1);
puts(str2);
while(str1[j]){
str3[i++]=str1[j++];
}
j=0;
while(str2[j]){
str3[i++]=str2[j++];
}
str3[i]='\0';
printf("After concatenation the strings are\n");
puts(str3);
return 0;
}

Anonymous said...

#include
#include
void main()
{
char s1[20],s2[20],si;
char*ps1,*ps2;
clrscr();
cout<<"enter 1 st";
cin>>s1;
cout<<"enter 2 nd";
cin>>s2;
ps1=&s1;
ps2=&s2;
while(ps1!='\0')
{
*ps1=*ps2;
ps1++;
ps2++;
}
*ps1='\0';
cout<<"copied string is";<<si;
}

Anonymous said...

THANK YOU SOO MUCH

Unknown said...

how can we write a program to read and display a 3*3 matrix using array of pointer in c? reply me today only as tomorrow is my paper.
how can we write a program read and display a 3*3 matrix using pointer to an array in c?

Md Muazzam said...

It is wrong because how it possible to modify the string present in code section?/???

Unknown said...

#include
#include

void concat(char *s1, char *s2)
{

char s3[100];char*p=s3;
while(*s1!='\0')
{
*p=*s1;
p++;
s1++;
}
while(*s2!='\0')
{
*p=*s2;
p++;
s2++;
}
*p='\0';
puts(s3);
}

int main()
{
char s1[50],s2[50];
gets(s1);
gets(s2);
concat(s1,s2);
return 0;
}

Unknown said...

it will work in all the condition

Unknown said...

u don't need to declare int j=0;
it will generate a warning...

Unknown said...

Very very Good example