Hello,
seems like I have a problem in passing an array to a function and then passing the value back to the main program.
This program reads a sentence and converts the first letter in a capital letter, if needed, and converts the rest in non capital.
I can't pass the word back to main. It signals an error.
I could as well make the function print the final sentence but that's not what I want.
Can anyone help me?
seems like I have a problem in passing an array to a function and then passing the value back to the main program.
This program reads a sentence and converts the first letter in a capital letter, if needed, and converts the rest in non capital.
Code:
#define maxarray 40
#include <stdio.h>
#include <string.h>
char change(char word[]);
void main()
{
char word[maxarray];
printf("\nIntroduce sentence ");
gets(word);
word=change(word);
printf("\nThe sentence is: %s", word);
}
char change(char word[])
{
int i;
if (( 97 <= word[0]) && (word[0] <= 122 ))
word[0] = word[0]-32;
for (i=1; i< maxarray; ++i)
{
if (( 65 <= word[i]) && (word[i] <= 90))
word[i]= word[i]+32;
}
return word;
}
I can't pass the word back to main. It signals an error.
I could as well make the function print the final sentence but that's not what I want.
Can anyone help me?