The function gets
is unsafe and is not supported by the C Standard. Instead you standard C function fgets
.
The function strcat
is declared the following way
char * strcat(char * restrict s1, const char * restrict s2);
That is it expects two arguments of the pointer type char *
that point to string literal. However the variable slash
is declared as having the type char
char str[100], slash = 'H';
Instead you should write the declaration the following way
char str[100], *slash = "H";
Now the variable slash
has the pointer type char *
and points to the string literal "H"
.
Pay attention to that you should guarantee that the array str
has a space to accommodate the string literal.
Also to output the returned value of the function strlen
you have to use the conversion specifier zu
instead of i
or d
printf("\n\n%s\n\n%zu\n\n", str, strlen(str));
Also bear in main that according to the C Standard the function main without parameters shall be declared like
int main( void )
Actually if you need to append only one character to a string then it can be done without the function strcat
the following way
#include <stdio.h>
#include <string.h>
int main( void )
{
char str[100], slash = 'H';
fgets( str, sizeof( str ), stdin );
size_t n = strcspn( str, "\n" );
if ( n != sizeof( str ) - 1 )
{
str[n] = slash;
str[++n] = '\0';
}
printf( "\n%s\n", str );
}