Solved

run time error

Posted on 2000-03-28
1
197 Views
Last Modified: 2010-04-02
I have the following program code that read a text file and store it into a array of structure declare as below
compliation is success but when runnung the program a error 'scanf : floating point formats not linked'

#include <stdio.h>
#include <string.h>
void main()
{
    struct score
    {
        float money;
        char name[4];
    };
    struct score ming[11];
    int count, index;
    int exchange_count, pass, check;
    int start, middle, end, found, value;
    char temp[4], input_data[4];

    FILE *fp;
    fp = fopen("datafile.txt","r");
    for ( count = 1; count <= 10; count++ )
     fscanf(fp,"%s  %f",&ming[count].name,&ming[count].money);
     fclose(fp);
}


0
Comment
Question by:adrianmak
1 Comment
 
LVL 33

Accepted Solution

by:
hongjun earned 20 total points
Comment Utility
Your fscanf should be in this way
fscanf("%s %f", ming[count].name, &name[count].money);

Another possibility is you must make sure that the records in your text file must be in the below standard:
name1 99
name2 88

Another problem in your program is that you should use the for loop in the below way
for ( count=0; count<10; i++ )
index for array starts at 0 and not 1. The above for loop will loop 10 times and occupy array from 0-9.
Another thing to make sure is that you should make sure that the text file has at least 10 records altogether.

I suggest you using the below loop to read the file
while ( !(feof(fp) )
{
    fscanf(...);
}

hongjun
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now