+ 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

24th Apr 2020, 7:23 PM
FS00047
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);
24th Apr 2020, 7:45 PM
andriy kan
andriy kan - avatar
+ 2
FS00047 what is your question? I don't understand it.
26th Apr 2020, 7:32 AM
Manthan Gohel
Manthan Gohel - avatar
+ 2
Vishnu Manoj That's not how it works in C.
26th Apr 2020, 7:34 AM
Manthan Gohel
Manthan Gohel - avatar
+ 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.
25th Apr 2020, 3:23 AM
andriy kan
andriy kan - avatar
+ 1
Ok, i will more into it.... By the way thanks...... 👍🏻
25th Apr 2020, 3:25 AM
DeWill
DeWill - avatar
0
andriy kan What does snprintf means...?
25th Apr 2020, 12:16 AM
DeWill
DeWill - avatar
0
Py. first_name = "Mike" last_name = "Scott" " ".join([first_name, last_name])
26th Apr 2020, 8:46 AM
John Denver
John Denver - avatar
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
26th Apr 2020, 12:24 PM
Amit singh
Amit singh - avatar
0
In java String a="Homer"; String b="Simpson"; System.out.print(a+" "+b); Thats it..
26th Apr 2020, 12:26 PM
Kamlesh Singh Kamlesh Singh
Kamlesh Singh Kamlesh Singh - avatar
- 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.]
25th Apr 2020, 12:58 PM
TAVISH
TAVISH - avatar
- 1
You can use + to contact For getting space String 3= string 1+(space) string 2
25th Apr 2020, 7:02 PM
Vishnu Manoj
Vishnu Manoj - avatar
- 1
Use concat operator or use arrays
26th Apr 2020, 4:37 PM
Eresh Bugide
- 1
"Firstname" , " " , "Surname" . I guess that might work
26th Apr 2020, 10:28 PM
Daryl Chibange