+ 1
How to concatenate two strings with a space [SOLVED]
First Name - Homer Surname - Simpson When strcat(Firstname, surname) is used it combies both without any spaces as《HomerSimpson》. Does anyone know a way of merging them with a space in between? Thanks
14 odpowiedzi
+ 8
char first_name[] = "Homer";
char surname[] = "Simpson";
#define MAX_SIZE 100
char result[MAX_SIZE];
snprintf(result, MAX_SIZE, "%s %s", first_name, surname);
puts(result);
+ 2
FS00047 what is your question? I don't understand it.
+ 2
Vishnu Manoj That's not how it works in C.
+ 1
DeWill
Print to a string.
snprintf is standard C library function which stores formatted output as string into the passed as first argument buffer.
+ 1
Ok, i will more into it....
By the way thanks...... 👍🏻
0
andriy kan What does snprintf means...?
0
Py.
first_name = "Mike"
last_name = "Scott"
" ".join([first_name, last_name])
0
THIS CONCEPT IS FOR
C PROGRAMING
1st include the header file
#include<string.h>
and use strcat() function which is use to concatenate c type string
https://code.sololearn.com/cRKhhbh7tkIO/?ref=app
https://code.sololearn.com/cRKhhbh7tkIO/?ref=app
0
In java
String a="Homer";
String b="Simpson";
System.out.print(a+" "+b);
Thats it..
- 1
In Python
x = "Hello "
y = "User"
print (x + y)
[I.e. you gotta give a space after hello or before user]
________________________
In js
var x = "Hello";
var y = " User";
console.log(x + y);
[Here I put space before user so that you get cleared.]
- 1
You can use + to contact
For getting space
String 3= string 1+(space) string 2
- 1
Use concat operator or use arrays
- 1
"Firstname" , " " , "Surname" .
I guess that might work