Thread: Creating a non-statndard function.

  1. #1
    Registered User
    Join Date
    Jan 2012
    Las Vegas, NV

    Cool Creating a non-statndard function.

    Hello, I have been having some difficulty finding the answer to creating your own simple function which is comprised of a few standard functions doing things in a way that is acceptable. What I am looking to do is creat a function that can be inserted into other functions that do standard things like the printf function. For example:

    printf ("character:""%c\n",sc);

    uses variable sc. I would like to be able to replace this with:

    printf ("character:""%c\n",myfunction(sc));

    so that what printf returns is the "modified" variable sc from what myfunction has done to it. So that you know, I am simply using the memset function to set the first character of sc after using a count from the strchr function.

    I asked this elsewhere and have gotten very short and unhelpful and rude responses. I am new to c++ programming and I'm not in school doing homework. I would like to find some input of how to properly structure my new function so that it can be used the way I intend. The requirement that I'm looking for is to be able to use my function in the place of a variable in where the function, myfunction(sc) can be used as myfunction(other_variables) to do the same thing. I'm having difficulty finding an example of how I can do this. Any help is certainly appreciated.

    Thank you.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Do you know how to create a function?

    What does this do?
    #include <stdio.h>
    char  myfunction(char x);
    int main()
        char sc = 'X';
        printf ("character:""%c\n",myfunction(sc));  
    And what do you expect to happen if some source file, within your project, includes this?
    #include <ctype.h>
    char myfunction(char x)
         if (islower(x))
             return toupper(x);
         else if (isupper(x))
             return tolower(x);
             return x;
    I realise I am answering your question with questions. However, take the time to ponder my questions (or, even copy the code fragments into source files) and you will be able to answer your questions.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    Do you know the difference between C and C++ (if not, google it!)? If so, you need to make up your mind on what language you want to use.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a Function
    By JonathanS in forum C Programming
    Replies: 13
    Last Post: 09-18-2011, 01:22 AM
  2. Creating an scanf function inside an function
    By anserudd in forum C Programming
    Replies: 4
    Last Post: 03-25-2011, 09:19 AM
  3. Creating Function Templates
    By marQade in forum C++ Programming
    Replies: 26
    Last Post: 12-03-2007, 04:07 PM
  4. Help creating function of sin cos and tan
    By Niz in forum C Programming
    Replies: 12
    Last Post: 01-09-2007, 05:55 PM
  5. Creating function
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 02-25-2002, 12:24 PM

Tags for this Thread