Structure return type is an incomplete type.

G

gk245

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.
 
G

gk245

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.
 
C

Christopher Benson-Manica

gk245 said:
#include <stdio.h>
#include <ctype.h>
#include <strings.h>

The header is said:
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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top