Hi i have a very simple code to read values from a file. However It isnt taking in all the values correctly. - #include <math.h>
-
#include <stdio.h>
-
-
int i[100000000];
-
int t,r;
-
-
main()
-
{
-
FILE *dat;
-
dat = fopen("ordered.dat","r");
-
-
r=1;
-
for(r=1;r<50;r++)
-
{
-
fscanf(dat,"%d",&i[r]);
-
printf("%d\n",i[r]);
-
-
}
-
-
}
Here are a list of the values i am using to read:
56
1516
211516
31121516
4112131516
511213141516
611213142516
512213141526
413213142516
412223241516
314213241516
412223241516
314213241516
412223241516
314213241516
412223241516
Would really appreciate any help you can give me, on why i am not getting these values when i read the file!
Thanks
2 1400
Hai ,
You just try this code,
#include <math.h>
#include <stdio.h>
double i[100];
int t,r;
main()
{
FILE *dat;
dat = fopen("ordered.dat","r+");
r=0;
for(r=0;r<50;r++)
{
fscanf(dat,"%d",&i[r]);
printf("%d\n",i[r]);
}
fclose( dat );
}
You are declared variable i as an integer first but when you are reading you are using type specifier as a double.
Cheers,
Kiruba.K
Hi i have a very simple code to read values from a file. However It isnt taking in all the values correctly. - #include <math.h>
-
#include <stdio.h>
-
-
int i[100000000];
-
int t,r;
-
-
main()
-
{
-
FILE *dat;
-
dat = fopen("ordered.dat","r");
-
-
r=1;
-
for(r=1;r<50;r++)
-
{
-
fscanf(dat,"%d",&i[r]);
-
printf("%d\n",i[r]);
-
-
}
-
-
}
Here are a list of the values i am using to read:
56
1516
211516
31121516
4112131516
511213141516
611213142516
512213141526
413213142516
412223241516
314213241516
412223241516
314213241516
412223241516
314213241516
412223241516
Would really appreciate any help you can give me, on why i am not getting these values when i read the file!
Thanks
Dude,
For an integer, typical size is 4 bytes which means it can store as much as 4,294,967,296./* calculated as 2 power (8*4) */ This doesn't mean you can store from 0 to 4,294,967,296, instead you can store from -2147483648 to +2147483647.
Now if you make a attempt to store 2147483648 in your program it will take as
-2147483648 and for 2147483648 --> -2147483647 and so on..
I hope this answered your question.
Regards,
Shaggy@FTF
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# to open a file and write to file
# do
f=open('xfile.txt','w')
# this creates a file "object" and name it f.
# the second argument of open can be
|
by: fabrice |
last post by:
Hello,
I've got trouble reading a text file (event viewer dump) by using the
getline() function...
After 200 - 300 lines that are read correctly, it suddenly stops
reading the rest of the...
|
by: Lionel B |
last post by:
Greetings,
I need to read (unformatted text) from stdin up to EOF into a char
buffer; of course I cannot allocate my buffer until I know how much
text is available, and I do not know how much...
|
by: Oliver Knoll |
last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode
(that is just writing, right?). How would one reopen it for reading?
I got the following (which works):
FILE *tmpFile =...
|
by: Rajorshi Biswas |
last post by:
Hi folks,
Suppose I have a large (1 GB) text file which I want to read in
reverse. The number of characters I want to read at a time is
insignificant. I'm confused as to how best to do it. Upon...
|
by: Need Helps |
last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
|
by: John Dann |
last post by:
I'm trying to read some binary data from a file created by another
program. I know the binary file format but can't change or control the
format. The binary data is organised such that it should...
|
by: blazedaces |
last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
|
by: efrenba |
last post by:
Hi,
I came from delphi world and now I'm doing my first steps in C++. I'm
using C++builder because its ide is like delphi although I'm trying to
avoid the vcl.
I need to insert new features...
|
by: Derik |
last post by:
I've got a XML file I read using a file_get_contents and turn
into a simpleXML node every time index.php loads. I suspect this is
causing a noticeable lag in my page-execution time. (Or the...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |