Solved

run-time error

Posted on 2000-03-28
2
188 Views
Last Modified: 2010-05-19
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
2 Comments
 

Expert Comment

by:sasson
ID: 2666130
Hi

U can try this code:


if (!((fp = fopen("datafile.txt","r"))==NULL))
{
    for ( count = 1; count <= 10;   count++ )
     fscanf(fp,"%s  %f",&ming[count].name,&ming[count].money);
     fclose(fp);
}
else
   printf("Error whatsoever....");

your file may not be opened.
0
 
LVL 10

Accepted Solution

by:
rbr earned 20 total points
ID: 2667831
USe
  fscanf(fp,"%s  %f",ming[count].name,&ming[count].money);

ming[count].name is already a pointer no & needed.

And some compilers have problems in using the floating point expansion.

Try
void main()
{
    float dummy=1.0;
as your first main line.
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why this code doesn't work? 8 108
Where is my core dump file in Ubuntu? 12 454
Problem with MFCApp 78 421
smtp c source code 7 87
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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

828 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