c - copying pointer characters not working as expected -


in following code, doing wrong? run code in eclipse , using mingw c compiler. when run eclipse stops responding. when debug code, breaks on line

*start = *end; 

i verified value of *start , *end in debug mode , none null.

void func1(char *str) {     char *end, *start;     end = start = str;     char tmp;      if (str)     {         while (*end)             ++end;         --end;          while (start < end)          {             tmp = *start;             *start = *end;             *end = tmp;              start++;             end--;         }     } } 

any tips/ideas?

so according feedback passing string literal, "hello world" func1, modifying string literal undefined behavior, alternatively use , work:

char arr1[] = "hello world" ; func1(arr1) ; 

although adam , kerrek pointed out need add more error checking code should fix immediate problem.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -