Monday, July 2, 2018

C program to concatanate Strings



#include <stdio.h>

void concatenate(char [], char []);

int main()
{
   char p[100], q[100];

   printf("Input a string\n");
   gets(p);

   printf("Input a string to concatenate\n");
   gets(q);

   concatenate(p, q);

   printf("String obtained on concatenation: \"%s\"", p);

   return 0;
}

void concatenate(char p[], char q[]) {
   int c, d;

   c = 0;

   while (p[c] != '\0') {
      c++;
   }

   d = 0;

   while (q[d] != '\0') {
      p[c] = q[d];
      d++;
      c++;
   }

   p[c] = '\0';
}

No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...