Help writing getstring function

Posted by volting on Stack Overflow See other posts from Stack Overflow or by volting
Published on 2010-04-14T22:12:50Z Indexed on 2010/04/14 22:23 UTC
Read the original article Hit count: 257

Filed under:
|

Im having some trouble writing a getstring function, this is what I have so far.

Regards, V

const char* getstring()
{


    char *buffer;
    int i = 255;

    buffer = (char *)malloc(i*sizeof(char));

    *buffer = getchar();
    while ( *buffer != '\n' )
    {
        buffer++;
        *buffer = getchar();
    }
    *buffer = '\0';

    const char* _temp = buffer;
    return _temp;
}


int main()
{
    char* temp = getstring();

    for ( ;temp++ ; *temp != '\0')
    {
        printf("%c", *temp);
    }

    return 0;
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about getstring