Thread: Reading Characters of an argument.

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    59

    Reading Characters of an argument.

    Greetings ,
    I wrote a function that will be removing non alpha characters and copy name or word for name .My problem is I am confused how to pass the argument or string to my function so that anywhere I call the function ,the function will know which of the string or argument to read .I need help on how to do this .This is my function.

    Code:
    int get_Name( char *name ) {
    
            int c;
            while( c = getchar()!=EOF && !isalpha(c) ) {
                ;
            }
            if( c == EOF ) {
                ;
            }
    
            *name = c;
            name = name + 1;
            while( c = getchar()!=EOF && isalpha(c)) {
                *name = c;
                name = name + 1;
            }
            *name = '\0';
            return 0;
        }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Functions should do one thing and do it well. If you want to write a function for "removing non alpha characters", then it should operate on the string by removing non-alphabetic characters. It should not also be reading from stdin.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    59
    Since arguments are strings ....Is there not any how I can pass an argument or string as a parameter to my function above ???

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by code_lover
    Since arguments are strings ....Is there not any how I can pass an argument or string as a parameter to my function above ???
    You can pass a string as an argument to your function. What exactly is the problem?

    The problem that I do see is what I pointed out to you: it is not about argument passing, but about what the function does.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading off characters
    By amie001 in forum C Programming
    Replies: 2
    Last Post: 06-07-2011, 12:36 AM
  2. Reading in single characters
    By pallum in forum C++ Programming
    Replies: 1
    Last Post: 11-13-2010, 12:55 AM
  3. Reading an hex offset from command-line argument
    By papagaio in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 06:36 AM
  4. reading characters
    By sara.stanley in forum C Programming
    Replies: 9
    Last Post: 02-12-2006, 06:07 PM
  5. Reading Characters.
    By Red Army in forum C++ Programming
    Replies: 4
    Last Post: 05-30-2002, 11:36 AM