I wrote a function to replace the blank spaces with tab character. But when I tried to implement it using function. I am quite not understanding how to call this function. I need functions
- Which takes string from user as input,
- Second function which replaces the blank space with tab character,
- Function to print the modified string.
I achieved second one:
void SecondFunction()
{
char string[] = "I am new to c";
char *p = string;
for (; *p; ++p)
{
if (*p == ' ')
*p = '\t';
}
printf(string);
}
And when I tried to call this function like:
int main()
{
SecondFunction("Hi s");
}
By changing my function to:
void SecondFunction(char* str)
{
char string[] = str;
char *p = string;
....
...etc
}
I get the following error:
error: invalid initializer
char string[] = str;
^
Please, can anybody help me to write the 3 functions of my requirement?
char string[] = str;You could dochar *string = str;but you don't need it. Just dochar *p = str;.printf(string)you should doprintf("%s", string); should your input value have%characters, your program would have undefined behaviour.