Structure return type is an incomplete type.

Discussion in 'C Programming' started by gk245, May 5, 2006.

  1. gk245

    gk245 Guest

    I have something like this:

    #include <stdio.h>
    #include <ctype.h>
    #include <strings.h>

    struct sentence get_sentence (char string[])
    {
    struct sentence my_sentence
    {
    int count_1;
    int count_2;
    int count_3;
    };

    // Add for-loop to count numbers, uppercase letters (isupper),
    //lowercase(islower), etc.

    return(mysentence)
    }

    However, even before i add the for-loop, i cannot compile it. An error
    comes up saying that the "return type is an incomplete type".
    Basically, the problem asked me to count the number of
    uppercase/lowercase letters and digits in a string. Then return that
    as a structure.

    Thanks.
     
    gk245, May 5, 2006
    #1
    1. Advertising

  2. gk245

    gk245 Guest

    gk245 submitted this idea :
    > I have something like this:
    >
    > #include <stdio.h>
    > #include <ctype.h>
    > #include <strings.h>
    >
    > struct sentence get_sentence (char string[])
    > {
    > struct sentence my_sentence
    > {
    > int count_1;
    > int count_2;
    > int count_3;
    > };
    >
    > // Add for-loop to count numbers, uppercase letters (isupper),
    > //lowercase(islower), etc.
    >
    > return(mysentence)
    > }
    >
    > However, even before i add the for-loop, i cannot compile it. An error comes
    > up saying that the "return type is an incomplete type". Basically, the
    > problem asked me to count the number of uppercase/lowercase letters and
    > digits in a string. Then return that as a structure.
    >
    > Thanks.


    Doh, nevermind, i was supposed to declare the structure and its members
    before the function starts, not inside of it.
     
    gk245, May 5, 2006
    #2
    1. Advertising

  3. gk245 <> wrote:

    > #include <stdio.h>
    > #include <ctype.h>
    > #include <strings.h>


    The header is <string.h>.

    > struct sentence get_sentence (char string[])
    > {
    > struct sentence my_sentence
    > {
    > int count_1;
    > int count_2;
    > int count_3;
    > };


    How do you expect this to work? The structure definition is contained
    within the function block; you're declaring get_sentence() to return a
    structure whose definition is not in scope. Your friendly C text can
    explain how to use incomplete types for fun and profit; you can also
    simply move your structure definition outside the function (and to an
    appropriate header file).

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, May 6, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Smith

    structure containing incomplete array type

    Eric Smith, Apr 9, 2004, in forum: C Programming
    Replies:
    6
    Views:
    3,486
    Kevin Bracey
    Apr 13, 2004
  2. xuthee

    tree data structure: incomplete type error

    xuthee, Jul 18, 2007, in forum: C Programming
    Replies:
    2
    Views:
    726
    xuthee
    Jul 19, 2007
  3. Replies:
    1
    Views:
    994
    Richard Bos
    Jan 17, 2008
  4. Luca Forlizzi

    Questions on incomplete structure type

    Luca Forlizzi, Nov 5, 2010, in forum: C Programming
    Replies:
    4
    Views:
    615
    Marcin Grzegorczyk
    Nov 5, 2010
  5. m0shbear
    Replies:
    1
    Views:
    535
    m0shbear
    Mar 19, 2011
Loading...

Share This Page