[Dev-C++] Problems with arrays of pinters
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Esteban V. <est...@ho...> - 2003-09-17 19:16:51
|
Hi, the next code has an running error, non a compiler error. Anybody can
understand it ?
thanks, Esteban
char str1[] = "Hello, how ";
char *str2 = "are you ?";
char *pstr[2];
// these works fine...
pstr[0] = str1;
pstr[1] = str2;
// these works fine...
printf("%s%s\n", pstr[0], pstr[1]);
// these works fine...
if(*pstr[0] == 'H')
printf("\"%s\" start with 'H'\n", pstr[0]);
if(*pstr[1] != 'x')
printf("\"%s\" don't start with 'X'\n", pstr[1]);
// I'm attempting to increment 'H' to 'I'.
// these works fine...
(*pstr[0])++;
printf("%s\n", pstr[0]);
// I'm attempting to increment 'a' to 'b'.
// these, doesn't works fine...
// these halts the computer... the same with (*(pstr[1]))++
(*pstr[1])++;
printf("%s\n", pstr[1]);
|