R
Ramaraj M Bijur
Hi All,
Could anyone help me to resolve following problem in C the IDE used is
Microsoft VC++,
Please let me know the which option in VC++ will do the needful
The problem statement:
overwrite of charcter in constatnt string like char *str="Hi
all"; str[3]='A'; the result of this str points to the string "Hi All"
code pragment
const char * const message[]={
(const char * const)"message -1",
(const char * const)"message -2",
(const char * const)"message -3",
(const char * const)"message -4",
(const char * const)"message -5"
};
int main()
{
int i=0;
char *ptr = (char *)message[1];
ptr[9]='1';
ptr = (char *)message[2];
ptr[9]='1';
ptr = (char *)message[3];
ptr[9]='1';
ptr = (char *)message[4];
ptr[9]='1';
for(;i<5;i++)
puts(message);
return 0;
}
the output is
message -1
message -1
message -1
message -1
message -1
with ragards
ramaraj
Could anyone help me to resolve following problem in C the IDE used is
Microsoft VC++,
Please let me know the which option in VC++ will do the needful
The problem statement:
overwrite of charcter in constatnt string like char *str="Hi
all"; str[3]='A'; the result of this str points to the string "Hi All"
code pragment
const char * const message[]={
(const char * const)"message -1",
(const char * const)"message -2",
(const char * const)"message -3",
(const char * const)"message -4",
(const char * const)"message -5"
};
int main()
{
int i=0;
char *ptr = (char *)message[1];
ptr[9]='1';
ptr = (char *)message[2];
ptr[9]='1';
ptr = (char *)message[3];
ptr[9]='1';
ptr = (char *)message[4];
ptr[9]='1';
for(;i<5;i++)
puts(message);
return 0;
}
the output is
message -1
message -1
message -1
message -1
message -1
with ragards
ramaraj