I am trying to understand this particular line of code.
I'm having trouble comprehending why there are 3 assignment statements needed for this. I figure it is the minimum necessary, I just can't seem to follow it with my mind.
If someone could take me through what each line of this does, in english, that would be fantastic.
Thanks.
void to_upper(char *word) {
int index = 0;
while (word[index] != '\0') {
word[index] = toupper(word[index]);
index++;
}
}
int length(char *word) {
int index=0;
while (word[index] != '\0')
index++;
return index;
}
void reverse(char *word) {
int index, len;
char temp;
len = length(word);
for (index=0; index<len/2; index++) {
temp = word[index];
word[index] = word[len-1-index];
word[len-1-index] = temp;
}
}
reverse, how would you do it with fewer assignments?to_upperandlengthare not really part of what you're asking about, are they?lengthinstead of just usingstrlen?