Tag: C: The contents of the character array are: "Student a Am I" is changed to "I am a student". can only open a limited space
#include <stdio.h>void my_reverse (int len, char arr[]) {int left =0; int right = len-1; while (left < right) {CH AR tmp = arr[left]; Arr[left] = Arr[right]; Arr[right] =tmp; Left + +; Right--; }}int Main () {char arr[] = "Tneduts a ma i"; int len =sizeof (arr)/sizeof (arr[0])-1; my_reverse (Len,arr); printf ("%s\n", arr ); return 0; }
Invert the string output.
First, sizeof is not the same as strlen, which asks for length, including the length of the string ending flag, and the true string length len is
=sizeof (arr)/sizeof (arr[0])-1; Use len-1 when determining the right length.
The void type here is because the problem only changes the string address, and does not do other transformations, so it does not need to return a value.
C Language: The contents of the character array are: "Student a Am I", the content is changed to "I am a student". Only a limited space can be opened.