Thread: Functions and Strings Question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    @ozumsafa, Don't use gets() see the FAQ. Consider not hardcoding the size of input, your also going out of bounds of valid data (ie overstepping the end of the string).

    consider:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        char input[BUFSIZ];
        size_t i = 0;
    
        fgets(input, sizeof(input), stdin);
        while(input[i] != '\0')
        {
            if(input[i] == '-')
                input[i] = '_';
    
            i++;
        }
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Jul 2007
    Posts
    3
    Thanks, guys! I'll try it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing strings to functions and modifying them
    By diddy02 in forum C Programming
    Replies: 6
    Last Post: 08-11-2008, 01:07 AM
  2. passing strings from functions as the "return" part
    By fraktal in forum C Programming
    Replies: 8
    Last Post: 12-13-2005, 01:38 AM
  3. Creating Functions that use Format control Strings
    By tzuchan in forum C Programming
    Replies: 6
    Last Post: 03-29-2004, 12:50 PM
  4. Functions that return strings? (help)
    By Nuke in forum C++ Programming
    Replies: 2
    Last Post: 05-18-2003, 09:04 PM
  5. Using Strings with Functions
    By DJH in forum C Programming
    Replies: 10
    Last Post: 10-19-2001, 04:40 PM