There are at least two serious errors.
The first one is that you may not change a string literal. Any attempt to change a string literal results in undefined behavior.
char *string = "Lol";
convert_lower(string);
The second one is that within the function the passed pointer is changed. so the function returns a pointer that points to the terminating zero instead of pointing to the beginning of the string.
And instead of casting to char
tolower((char)*word)
you need to cast to unsigned char
tolower( (unsigned char)*word)
The function can be defined like
char * convert_lower( char *word )
{
for ( char *p = word; *p; ++p )
{
*p = tolower( ( unsigned char )*p );
}
return word;
}
and called like
char string[] = "Lol";
puts( convert_lower(string) );
If you want to make a copy of the original string converting all characters to the lower case then the function can look the following way
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
//...
char * convert_lower( const char *word )
{
char *result = malloc( strlen( word ) + 1 );
if ( result != NULL )
{
char *p = result;
while ( ( *p++ = tolower( ( unsigned char )*word++ ) ) != '\0' );
}
return result;
}
And the function can be called like
char *string = "Lol";
char *lower_case_string = convert_lower( string );
if ( lower_case_string != NULL ) puts( lower_case_string );
free( lower_case_string );