webForumDet fria alternativet

Koppla ihop strängar.

C/C++ur C/C++

2 svar · 245 visningar · startad av The_datanörd

The_datanördMedlem sedan feb. 200411 inlägg
#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"

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

"hello world" finns nu i tvo.

/Viktor

PeWMedlem 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>
130 ms totalt · 3 externa anrop · v20260731065814-full.29ac60f6
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
127 ms — hämta tråd, inlägg och bilagor (db)