is it possible to change the space into underline?

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

please help!!

Recommended Answers

All 3 Replies

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.

"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"

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,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.