You are not logged in.

#1 2004-07-29 21:26:00

Fox
Member
Registered: 2004-07-28
Posts: 124

[C] Spliting an Array

I have the folowing array:

char *message = "hello";

or 

char message[] = "hello";

How to split the array/string in its characters (char message [0] = "h", etc)?

Offline

#2 2004-07-30 05:19:09

jochen
Member
From: Germany
Registered: 2004-06-01
Posts: 102

Re: [C] Spliting an Array

Hi,
I'm not sure if I understand you correctly. But a string/array of characters is already split in its characters.

char m[] = "Hello";
char c;

m[1] = 'E';

printf("%sn",m); // HEllo

c = m[2];

printf("%cn",c); // l

Offline

#3 2004-07-30 11:55:53

Fox
Member
Registered: 2004-07-28
Posts: 124

Re: [C] Spliting an Array

jochen wrote:

Hi,
I'm not sure if I understand you correctly. But a string/array of characters is already split in its characters.

char m[] = "Hello";
char c;

m[1] = 'E';

printf("%sn",m); // HEllo

c = m[2];

printf("%cn",c); // l

I did this like you but I use %s instead of %c so it couldn't work. But thanks for helping me.

Offline

Board footer

Powered by FluxBB