I am new to c programming language. I am trying to reverse elements in char array. Actually, I almost reversed but there is something that I can't make it. Here is code:
void q2_reverseTheArray(char word[100]){
int lentgh=sizeof(word);
int j;
for(j=length+1; j>=0; j--){
printf("%c", word[j]);
}
The code reverse the array but it adds another letter.
length; then it should crash because you start the loop by accessingword[length + 1]which is 2 indices out of range.for (j=length-1; j>0; j--)This will start at the last character and repeat until the first one. Better yet, become accustomed to using your debugger.