scanf error? arrays, structs

This is a discussion on scanf error? arrays, structs within the C Programming forums, part of the General Programming Boards category; when i run the program, it'll printf the prompts in the function get_element up until "enter electrons"...where an error says ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    6

    scanf error? arrays, structs

    when i run the program, it'll printf the prompts in the function get_element up until "enter electrons"...where an error says "6002- float point not loaded"

    first of all what does this mean,
    and then is there something wrong withy my scanf at that point?

    p.s. I don't quite grasp the logic to putting the user input into the array electrons[7], so if you can help, let me know...



    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    
    
    typedef struct{
    	int atomic_num;
    	char element[20];
    	char symbol[2];
    	char type[20];
    	double atomic_weight;
    	int electrons[7];
    } element_t;
    
    element_t get_element(void);
    
    
    
    
    int main(void)
    {
    
    	element_t elem;
    	elem = get_element();
    
    	return(0);
    
    }
    
    element_t get_element(void)
    {
    	element_t elem;
    	int i = 0;
    
    	printf("enter atomic number:");
    	scanf("%d", &elem.atomic_num);
    	printf("\nenter element name:");
    	scanf("%s", elem.element);
    	printf("\nenter symbol:");
    	scanf("%s", elem.symbol);
    	printf("\nenter type:");
    	scanf("%s", elem.symbol);
    	printf("\nenter atomic weight:");
    	scanf("%lf", &elem.atomic_weight);
    	printf("\nenter electrons:");
    	scanf("%d", &elem.electrons[]);
    	
    	return(elem);
    }

  2. #2
    .........
    Join Date
    Nov 2002
    Posts
    303
    This
    Code:
    scanf("%d", &elem.electrons[]);
    Should be
    Code:
    scanf("%d", &elem.electrons[0]);
    You needed to specify an element thats all

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  2. better way to scanf of a array of structs member?
    By stabu in forum C Programming
    Replies: 3
    Last Post: 07-17-2008, 05:51 PM
  3. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  4. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 05:34 AM
  5. Searching structs...
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 08-25-2001, 01:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21