webForumDet fria alternativet

Koppla ihop strängar.

C/C++

2 svar · 247 visningar · startad av The_datanörd

Medlem sedan feb. 200411 inlägg
Frågan#1

char hej[5];
char nej[5];
char hej[] = "hello";
char nej[] = "world";
char tvo[10];

nu vill ja kopla ihop hej[] och nej[] så dom blir som en , tvo[]
ska innehålla "hello world"

Medlem sedan aug. 20021 752 inlägg
#2
strcpy(tvo,hej);
strcat(tvo," ");
strcat(tvo, nej);

"hello world" finns nu i tvo.

/Viktor

Medlem sedan juni 200010 432 inlägg
#3

Du måste även inkludera string.h i din fil för att komma åt de funktioner som Viktor tipsade om:

#include <string.h>
251 ms totalt · 4 externa anrop · v20260731065814-full.1dc6f849
122 ms — deklarationer (db)
0 ms — hämta statistik (cache)
126 ms — hämta tråd, inlägg och bilagor (db)
119 ms — ändringar (db)