Thread: Error in an array of structures program

  1. #1
    Registered User Sid_TheBeginner's Avatar
    Join Date
    Jun 2012
    Location
    India
    Posts
    19

    Post Error in an array of structures program

    Hello guys. I'm getting this error:

    a.c: In function ‘main’:
    a.c:10:2: error: expected ‘;’, identifier or ‘(’ before ‘int’
    make: *** [a] Error 1

    I'm not able to figure it out. Please help. Sorry if its some silly error somewhere. I'm just not able to figure out

    Thanks in advance.

    Here's my code:
    Code:
    #include<stdio.h>
    
    
    int main(void)
    {
    	struct people {
    		char *name;
    		int id;
    	}
    
    
    	int i = 0;
    	struct people info[2];
    
    
    	for(i = 0; i < 2; i++) {
    		printf("Details for person %d\n", i+1);
    		printf("Name: ");
    		scanf("%s", info[i].name);	
    		printf("ID: ");
    		scanf("%d", &info[i].id);
    	}
    	printf("------------------------\n");
    	printf("--------DETAILS---------\n");
    
    
    	for(i = 0; i < 2; i++) {
    		printf("Name %d: %s\n", i, info[i].name);
    		printf("ID %d: %d\n", i, info[i].id);
    		printf("Name %d: %s\n", i, info[i].name);
    		printf("ID %d: %d\n", i, info[i].id);	
    	}
    
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Missing semi colon
    Code:
        struct people {
            char *name;
            int id;
        };
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Program: Array Structures
    By Jack23 in forum C Programming
    Replies: 11
    Last Post: 07-25-2012, 09:37 PM
  2. C++: Help with program using array structures
    By We'reGeeks in forum C++ Programming
    Replies: 5
    Last Post: 11-29-2010, 01:47 AM
  3. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  4. Initializing array of structures causing bus error
    By Aaron M in forum C Programming
    Replies: 5
    Last Post: 03-05-2006, 01:40 AM
  5. l-value error with structures
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 03-06-2002, 02:52 AM