Function of a string

I was asked to write a function that takes a 10-size array and complements any word less than 10 with exclamation marks for example:
“enter word:”
hello
printf:
hello!!!
I was able to write the code but i dont know how to put it in function.
this is my code
#include <stdio.h>

int main()
{
int index = 0;
printf(“Enter word \n”);
char a_word[10] = {};
scanf("%s", a_word);
printf("%s => “,a_word);
while (index < 9)
{
if (a_word[index] == ‘\0’)
a_word[index] = ‘!’;
index++;
}
printf(”%s",a_word);
return 0;
}

i really hope for some help with how to do it in funcion ,i also add my attempt to do that

#include <stdio.h>
char *word();
int main()
{
printf(“Enter word \n”);
word();
printf("%s => ",word());

return 0;

}
char *word()
{
int index = 0;
char a_word[10] = {};
scanf("%s", a_word);
while (index < 9)
{
if (a_word[index] == ‘\0’)
a_word[index] = ‘!’;
index++;
}

return a_word;

}

Thanks bro, It’s amazing.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.