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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -