Is it possib le to incremennt a pointer value (not the address)

Hello guys, is it possible to increment the pointer value like this?

1
2
3
4
5
6
7
8
9
  int main(){
    char* str = "Hello WoRLd! Today’s temperature is 34°C.";
        while(str != '\0'){
            (*str) += 32;
            str++;
        }
    printf("%s\n", str);
    return 0;
}


Because it gives me a Segmentation fault.. am i doing wrong?
Thanks in advice.
Most of your code is illegal.

Not sure what you are trying to do, but ...
1
2
3
4
5
6
7
8
9
10
11
12
#include <cstdio>
int main()
{
   char s[] = "Hello WoRLd! Today's temperature is 34øC.";
   char *str = s;
   while( *str != '\0')
   {
       (*str) += 32;
       str++;
   }
   printf("%s\n", s);
}
The string "Hello WoRLd! Today’s temperature is 34°C.", which str points to, is kept in read-only memory, so when you try to write to it, the system kills your program.
You can tell the compiler to make a copy of it in writable memory and then get a pointer to it:
1
2
char string[] = "Hello WoRLd! Today’s temperature is 34°C.";
char *str = string;
The rest of the code will be valid then.
Yes, it is possible to modify the content pointed to.

What you are doing wrong is modifying read only memory which that "Hello world" string literal is. An expression like line 2 should at least give a warning like this:

warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
Ok i fixed, thanks to you guys!!!!!! :DDD
Topic archived. No new replies allowed.