I'm trying to complete an assignment. What is meant by the term "modifying in-place without creating a copy" and "return value is the same value that was passed into the function"?
How do I check if my code satisfies both condition?
// converts all lowercase into uppercase
char* mystrupr(char *string)
{
int myStrlen = strlen(string);
for (int i = 0; i < myStrlen; i++)
if (string[i] >= 'a' && string[i] <= 'z')
*(string + i) -= 32;
return string;
}
I'm assuming that I had violated the conditions as when I was using this function in another part of my program, it gave me the errors:
passing argument 1 of 'mystrupr' discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
note: expected 'char *' but argument is of type 'const char *'
said code fragment that uses the uppercase function:
int spellcheck(char const *word) {
.
.
mystrupr(word);
.
.
}
*edit (making a copy)
int spellcheck(char const *word) {
.
.
char *myWord = word
mystrupr(myWord);
.
.
}