Thread: trouble with structure

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    17

    trouble with structure

    I'am just starting with programming a code with structure. I need some input on the bottom four lines of codes., why wouldn't it read in the values. Seems to work fine, up to that point.

    Code:
    #include <stdio.h>
    
    #define grade_test 3
    
    struct graderecord
    {
    	char name[21];			
    	char id_num[12];
    	float test[grade_test];
    	float final;
    	float homework;
    	float total;
    };
    
    
    void read_in_students(struct graderecord *std_ptr);
    
    int main(void)
    {
    	struct graderecord grades;
    
    	read_in_students(&grades);
    }
    
    void read_in_students(struct graderecord *std_ptr)
    {
    	int i,j,num_students;
    
    	printf("Number of students in class:");
    	scanf("%d",&num_students);
    
    	/* Input information about students */
    	for (i = 0; i < num_students; i++)
    	{
    		printf("Enter student name #%d: ", i+1);
    		scanf("%s", std_ptr->name);
    
    		printf("Enter student id number: ");
    		scanf("%d",std_ptr->id_num);
    		
    		for (j = 0; j < grade_test; j++)
    		{
    			printf("Enter score on test #%d: ", j+1);
    			scanf("%f", std_ptr->test);
    		}
    	
    		printf("Enter homework score; ");
    		scanf("%f", &graderecord.homework);
    		
    		printf("Enter the final exam score: ");
    		scanf("%f",&grade.final);
    		
    	}	
    	
    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Make sure you use the correct directives and arguments with scanf. For example,
    Code:
    scanf("%d",std_ptr->id_num);
    std_ptr->id_num is not an int.

    [edit]
    Code:
    scanf("%f", &graderecord.homework);
    Code:
    scanf("%f",&grade.final);
    Know your variable names and types.

    [edit=2]
    Code:
    void read_in_students(struct graderecord *std_ptr)
    {
    	int i,j,num_students;
    
    	printf("Number of students in class:");
    	scanf("%d",&num_students);
    
    	/* Input information about students */
    	for (i = 0; i < num_students; i++)
    	{
    		printf("Enter student name #%d: ", i+1);
    		scanf("%20s", std_ptr->name);
    
    		printf("Enter student id number: ");
    		scanf("%11s",std_ptr->id_num);
    		
    		for (j = 0; j < grade_test; j++)
    		{
    			printf("Enter score on test #%d: ", j+1);
    			scanf("%f", &std_ptr->test[j]);
    		}
    	
    		printf("Enter homework score; ");
    		scanf("%f", &std_ptr->homework);
    		
    		printf("Enter the final exam score: ");
    		scanf("%f",&std_ptr->final);
    	}	
    }
    [edit=last call]And note that you are reading all of these records into a single record.
    Last edited by Dave_Sinkula; 03-14-2006 at 10:37 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    136

    Thumbs up Floating point format not linked...isn't it

    Hi,

    the Error must be coming in your program is

    "Floating points format not linked. abnormal program termination."
    the reson for this error is....

    Some compilers for small machines, including Turbo C (and Ritchie's original PDP-11 compiler), leave out certain floating point support if it looks like it will not be needed. In particular, the non-floating-point versions of printf and scanf save space by not including code to handle %e, %f, and %g. It happens that Borland's heuristics for determining whether the program uses floating point are insufficient, and the programmer must sometimes insert a dummy call to a floating-point library function (such as sqrt; any will do) to force loading of floating-point support.

    A partially-related problem, resulting in a similar error message (perhaps ``floating point not loaded'') can apparently occur under some MS-DOS compilers when an incorrect variant of the floating-point library is linked. Check your compiler manual's description of the various floating-point libraries.
    S_ccess is waiting for u. Go Ahead, put u there.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Hi,

    the Error must be coming in your program is

    "Floating points format not linked. abnormal program termination."
    That's your error. I imagine that if the OP fixed what Dave_Sinkula noted it might work properly.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  2. Structure trouble...
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 06-25-2006, 12:40 AM
  3. trouble understanding the source file structure
    By Mario F. in forum C++ Programming
    Replies: 5
    Last Post: 05-26-2006, 06:46 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM