I just started teaching myself c with a book called practical c programming, and i can't figure out one of the exercises. I'm supposed to write a function that scans a character array for the character - and replace it with _. I tried doing it, but i don't think i fully understand how to pass arrays between functions or whatever. Here's what i got, please help me.
char replace(char string[100])
{
int i; //increment
for (i=0; string != '\0'; i++)
{
if (string[i] == '-')
string[i] = '_';
}
return(string[i]);
}
int main()
{
char line[100];
printf("Enter a string: ");
fgets(line, sizeof(line), stdin);
printf("New string: %s", replace(line));
}