[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to read long interger?

Posted on 2000-05-16
3
Medium Priority
?
210 Views
Last Modified: 2010-04-15
I am writting a program and I use sscanf to read data from a file:

sscanf(line, "%ld %lf\n", &a, &b);

The fiel contains data like following:

6000000.000  0.734581
23900000000.000  0.674805  
24000000000.000   0.606476  
24100000000.000   0.521484  

As I read in the first line, it's ok. But from the second line, I got problem. The a is not the value it is but -1869635475. It's an error. It seems the integer is too big. How can I solve the problem?
0
Comment
Question by:chenwei
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 80 total points
ID: 2813625
23900000000 does not fit in a 32 bit integer. Unless your system supports 36 or 64 bit integers, you may want to scan  %lf instead.
0
 
LVL 4

Expert Comment

by:wylliker
ID: 2814328
The limit is  4,294,967,295 for unsigned long values and 2,147,483,647 for signed long values.

You would have to read in your line differently and deal with creating your own math routines if you have to deal with these numbers as non-floats or non-doubles (i.e. integers) in calculations.

You could, for example take the right-most 9 characters and keep track of that as Billionths and the remaining left-most characters as Billions.
Your numbers would become a struct ...

struct _UglyNumber
{
   unsigned long billionths;
   unsigned long billions;
   unsigned short sign;
}

You would probably do better to use a float or double.

0
 
LVL 4

Expert Comment

by:captainkirk
ID: 2815274
looks like these values are floats, not integers... use the %lf as ozo suggested...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them 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.

656 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