Answers for "how to concatenate two strings in c without using strcat"

C
1

c concatenate strings without using strcat or strcpy

#include <stdio.h>
int main()
{
   char str1[50], str2[50], i, j;
   
   scanf("%s",str1);
   scanf("%s",str2);
   
   for(i=0; str1[i]!='\0'; ++i); 
 
   for(j=0; str2[j]!='\0'; ++j, ++i)
   {
      str1[i]=str2[j];
   }
   str1[i]='\0';
   printf("\n%s",str1);
   
   return 0;
}
Posted by: Guest on June-29-2021
12

c concatenate strings

char str[80];
strcpy(str, "these ");
strcat(str, "strings ");
strcat(str, "are ");
strcat(str, "concatenated.");
Posted by: Guest on March-22-2020
4

concatenate two strings in c

#include <stdio.h>
#include <string.h>
int main()
{
  char a[1000], b[1000];

  printf("Enter the first string\n");
  gets(a);

  printf("Enter the second string\n");
  gets(b);

  strcat(a, b);

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

  return 0;
}
Posted by: Guest on May-10-2020
1

program to concatenate two strings in c

// this program is to contenate strings without using string function

#include <stdio.h>
#include <string.h>

void concatenate(char *str1, char *str2)
{
    int i = strlen(str1), j = 0;

    while (str2[j] != '\0')
    {
        str1[i] = str2[j];
        i++;
        j++;
    }

    str1[i] = '\0';  // declaring the end of the string
}

int main()
{
  char string1[20], string2[20];
  gets(string1);
  gets(string2);
  
  concatenate(string1, string2);
  
  printf("String 1 : ");
  puts(string1);
  
  return 0;
}
Posted by: Guest on August-28-2020

Code answers related to "how to concatenate two strings in c without using strcat"

Code answers related to "C"

Browse Popular Code Answers by Language