Thread: Not recognizing structure member

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    1

    Not recognizing structure member

    Hi there,
    I'm having a problem with sending data to my structured variables. I'm pretty sure the structure is set up correctly, and the piece I'm working on is to get a string input from the user up to 20 characters, and then send that string to the char input[21] in the structure of the respective variable.
    The problem I run into is when I'm trying to compile the code, it tells me, there is no such member "input".

    Here is the code I am testing to get this working correctly, any input would be greatly appreciated! Thanks!

    The program I am working on is to replicate that of a JK Flip-Flop with J,K, and CLK as user inputs.

    Code:
    struct hilo
    {
    	char hi = "/***\\";
    	char lo = {'_', '_', '_', '_', '_'};
    	char input[21];
    };
    int main(void)
    {
    	struct hilo j, k, clk, q, qnot;
    	int i;
    	printf("This program is intended to take user inputs for J,K and CLK and show the graphs for each input and output.\n\n");
    	printf("Input a binary string up to 20 characters for the J input: ");
    	gets(j.input);
    	printf("Input a binary string up to 20 characters for the K input: ");
    	gets(k.input);
    	printf("Input a binary string up to 20 characters for the CLK input: ");
    	gets(clk.input);
    	printf("J input: %s\n", j.input);
    	printf("K input: %s\n", k.input);
    	printf("CLK input: %s\n", clk.input);
    	return 0;
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    I'm betting the compiler is complaining about more than that... Look at your two char definitions... You create a single character then try to stuff a string into one and an array into the other... These also need to be arrays.

    Moreover; you can't initialize the individual variables in a structure in that manner...
    You need to declare the structure and initialize it when you are creating instances.
    What you have fails because the prototype of the struct has no memory assigned to it.
    Code:
    struct hilo
    {
    	char hi[6];
    	char lo[6];
    	char input[21];
    };
    int main(void)
    {
    	struct hilo j =   <--- initialize here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. member of a structure that is a stucture member
    By MK27 in forum C Programming
    Replies: 2
    Last Post: 11-29-2008, 10:33 AM
  2. Regarding accessing the structure member
    By kollurisrinu in forum C Programming
    Replies: 5
    Last Post: 06-18-2008, 04:51 AM
  3. point to a structure member
    By behzad_shabani in forum C Programming
    Replies: 5
    Last Post: 06-12-2008, 03:59 AM
  4. structure member initialization
    By ivandn in forum C Programming
    Replies: 4
    Last Post: 10-27-2001, 01:27 PM
  5. structure member values
    By breed in forum C Programming
    Replies: 3
    Last Post: 10-25-2001, 06:20 AM