Error implementation in GCC:
char* strupr( char *str )
{
while(*str) {
*str++ = toupper(*str);
}
}
Note that str
is used twice in assignment .
Error implementation in GCC:
char* strupr( char *str )
{
while(*str) {
*str++ = toupper(*str);
}
}
Note that str
is used twice in assignment .
There are 2 problems: adding the pointer there will generate an undefined behavior and is not returning anything, have to change the signature of the function or return something. This works:
#include <stdio.h>
#include <ctype.h>
void strupr(char *str) {
while (*str) {
*str = toupper(*str);
str++;
}
}
int main(void) {
char texto[] = "teste";
strupr(texto);
printf("%s", texto);
return 0;
}
See running on ideone .