0

is it possible to change the space into underline?

coz i don't know how to program that in C...

please help!!

4
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by ~s.o.s~
0

If a character is a string, change it to an underscore. Later, rinse, repeat (if necessary).

Post an attempt. Read the announcement in this forum if you need clarification of my last statement.

0

"If a character is a string, change it to an underscore"
I guess Dave meant
"If a character is a space, change it to an underscore"

0

Maybe something along these lines should do the job in a simple way.

char* changeString (char* sourceStr)
{
    char* tmpStr = sourceStr;
    int strLength = strlen (tmpStr) - 1;
    for (int i =0; i < strLength; ++i) {
        if ( *(tmpStr + i) == ' ')
            *(tmpStr + i) = '_';
    }
    return tmpStr;
}

int main () {
    char name[BUFSIZ];
    fputs ("\nEnter the string: ");
    fgets (name, BUFSIZ, stdin);
    fputs ("\nThe new string is: ", stdout);
    fputs (changeString(name), stdout);
    getchar ();
    return 0;
}

Hope it helped,
Bye.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.