Thread: function

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    17

    Talking function

    There is a function again. I have no idea to do that.

    Write a function which copies a string into a new string(allocation new memory in the process)such that any lower case characters are converted to upper case(all other characters are coped unaltered) and returns a pointer to that string. The prototype is :

    char *strupper(const char *lower);

    I know how to allocate memory to something.
    but I am little bit confuse that char *strupper(...)
    Does it mean that it will return a pointer?

    how to achieve it?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    22

    Thumbs up Re: function

    Originally posted by Tombear
    There is a function again. I have no idea to do that.

    Write a function which copies a string into a new string(allocation new memory in the process)such that any lower case characters are converted to upper case(all other characters are coped unaltered) and returns a pointer to that string. The prototype is :

    char *strupper(const char *lower);

    I know how to allocate memory to something.
    but I am little bit confuse that char *strupper(...)
    Does it mean that it will return a pointer?

    how to achieve it?
    hi tombear,

    exactly it will return, if u use the below statement---

    return *string;

    here the variable 'string' must store the value of 'lower'.
    Jackie

  3. #3
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    if you return a pointer to a string in a function you need to declare the string as static otherwise it will be lost when the function returns and you will have a pointer to nothing.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It goes like this
    Code:
    char *strlower ( char *text ) {
        char *result = malloc( strlen(text) + 1 );
        if ( result == NULL ) return NULL;
        // do the actions asked
        return result;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM