+ 1
How can I concatenate a given string with a string I take as input?
8 Respostas
+ 2
you can use strcat function.
#include<string.h>
main()
{
  char s1[100] , char s2[] = "string 2";
  scanf ("%s", s1);
 strcat(s1,s2);
}
in s1 string in we have to concatenate, s2 which string is to concatenate.
final concatenated string will be s1.
[EDIT]: or if you want to implement it from scratch, you can do it using loops.
+ 8
you can use string function in c , like : strcat() function is used to join two strings, 
https://www.programiz.com/c-programming/library-function/string.h/strcat
+ 1
c
+ 1
plz tell me using + operator
+ 1
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
    int i = 4;
    double d = 4.0;
    char s[] = "HackerRank ";
     // Declare second integer, double, and String variables.
    int a,j=0,k=0;
    double b;
    char c[105],s3[105];
    // Read and save an integer, double, and String to your variables.
    scanf("%d\n",&a);
    scanf("%lf\n",&b);
    scanf("%s",c);
    //scanf("%*[^\n]%*c", &c);
    // Print the sum of both integer variables on a new line.
    printf("%d\n",i+a);
    // Print the sum of the double variables on a new line.
    printf("%.1f\n",d+b); 
    // Concatenate and print the String variables on a new line
    // The 's' variable above should be printed first.
   
    printf("%s",s);
    printf("%s",c);
    return 0;
}
+ 1
You must enter an integer a double and a string. It will add the numbers and concatenate the strings. but in this case only first word of the string concatenates the rest don't. please correct it
0
different language has different ways to do.
specify for which language you are asking.
0
Naqvi Viyank  c doesn't follow the oops concepts, so you can't overload the + operator in c,
but yes you can do it in cpp.
in python and some other languages, it's already handy given to you.






