debugging - Find bug in the C Program to Reverse a String -


I have written the following code to reverse the string. But this is giving some error to reverseStr () < / Code> The function is trapped after calling. I'm unable to find the bug. Can someone help me?

  #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; Four * reversal (four * str) {int i, len = 0; While (str [len]! = NULL) {len ++; } LAN- = 1; Four floating; (// printf ("% d% d% s \ n", i, len, str); temp = str [len-i] for (i = 0; i & lt; len / 2; i ++) ; Str [lane-i] = str [i]; str [i] = floating; // printf ("% d% d% s \ n", i, lane, str);} return str;} int main Zero) {char * str = "abcdefg"; Printf ("original ::% s \ n", str); str = reversestroke (str); printf ("reverse:% s", str); return 0;}   

As suggested by P0W, if you change from str * str [] then this work There is no need to return any strings because you are going through this context, so changes will be made on this. The code below is:

  #include  gt; add & lt; stdlib.h & gt; zero reversal (four * str) {int i, len = 0; while (str [len]! = NULL) for {len ++;} LAN- = 1; four floating; (I = 0; i & lt; len / 2 + len% 2; i ++) (// printf ("% d% d% s \ n", i, len, str); temp = str [len-i]; str [lane-i] = str [i]; str [i] = temporary ; // printf ("% d% d% s \ n", i, lane, str); }} Int main (zero) {char str [] = "abcdefg"; Printf ("original:% s \ n", str); ReverseStr (STR); Printf ("Reverse:% s", str); Return 0; }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -