Reading each char of a string

Started by
9 comments, last by stealth 21 years, 10 months ago
quote:
[source
for(int i=0;i<4;i++)
printf("%c ",string);
[/source
i''m not sure about c-style, i compile in cpp! ;-)


In C, you cannot declare variables in a program section, you must do it at the beggining, so that for(int i=...) is incorrect:


  // Declarationsint i;// Codefor (i=0;i<4;i++) printf ("%c",string[i]);  


By the way, in C++ is not neccesary to use string.h to get an unique char from a pointer. Just use an asterisk to interpretate that "pointer to char" as a "char":

[souce]
char String[5]="Soul";
char *pString = String;
while (*pString != ''\0'')
{
cout << *pString;
}
[/source]

Real programers are not afraid from maths! (I am)
(from an Asfixia Member I think)
JJpRiVaTe (Private Zone)
-=[ J ]=-I always forget to change the tagline.

This topic is closed to new replies.

Advertisement