473,383 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

reading using fread

how do i read from a text file using fread
Sep 19 '06 #1
3 11977
Banfa
9,065 Expert Mod 8TB
This question doesn't readdy make sense without more detail

1. Open the file with fopen
2. Read it with fread
3. Close the file with fclose

Expand|Select|Wrap|Line Numbers
  1. FILE fin = fopen( "FileName.txt", "r");
  2. char text[100];
  3.  
  4. fread(text, sizeof text, 1, fin);
  5.  
  6. fclose(fin);
  7.  
Of course that code has no error handling.
Sep 19 '06 #2
i am reading from a csv file.
i need to read each column separetly.
so i can sort the data of the column and use later.
the following is a part of the file i am reading;
BHP,"30 Sep 2002",9.14,9.2,9.05,9.05,16923879

BHP,"01 Oct 2002",9.1,9.29,9.07,9.29,8906781

BHP,"02 Oct 2002",9.5,9.54,9.35,9.39,14950825

BHP,"03 Oct 2002",9.39,9.39,9.21,9.24,8216758

BHP,"04 Oct 2002",9.25,9.28,9.18,9.28,6636304

BHP,"07 Oct 2002",9.22,9.33,9.14,9.22,3725225

BHP,"08 Oct 2002",9.1,9.16,9.05,9.14,9675060
i want to read the second column and sort the data in the column in respect to date.
i am using c language/
Sep 20 '06 #3
risby
30
i am reading from a csv file.
i want to read the second column and sort the data in the column in respect to date.

Perhaps you missed my answers to the same question which you asked yesterday.

Regarding the inappropriate use of fread() for csv files:
http://www.thescripts.com/forum/post2097892-11.html

and regarding separating fields in a csv file using fgets() and strtok()
http://www.thescripts.com/forum/post2098535-4.html
Sep 20 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

19
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...
2
by: JS | last post by:
Hello all! I have come on to a problem for which I am not able to find a solution searching the web. What I am trying to do is reading a log-file with a size of 1.3 GB. When reading it using...
3
by: syntax | last post by:
hi, i want to read a file using fread() in equal chunks through a for loop so that at the last call i dont get error..which way, i should read it? let me give an example, suppose i have 100...
4
by: Matthew Crema | last post by:
Hello, Say I have 1000 text files and each is a list of 32768 integers. I have written a C program to read this data into a large matrix. I am using fopen in combination with fscanf to read...
21
by: EdUarDo | last post by:
Hi all, I'm not a newbie with C, but I don't use it since more than 5 years... I'm trying to read a text file which has doubles in it: 1.0 1.1 1.2 1.3 1.4 2.0 2.1 2.2 2.3 2.4 I'm doing...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
3
by: juleigha27 | last post by:
Hi, First off, I want to apologize if this already got posted it seemed like something happened when I tried to post it previously and it didn't work. I am new to file manipulation with c. I...
16
by: Jm.GlezdeRueda | last post by:
Hi all, Im trying to read a 24bit bmp with fread, and i have some problems.. I want to read the whole structure in one time, but i dont know why, it only reads the first member well.. I have...
4
by: Giacomo | last post by:
Hello.. i'm using php on linux --version: PHP 5.2.5 (cli) (built: Apr 25 2008 18:40:41) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies and...
6
by: jcasique.torres | last post by:
Hi everyboy. I trying to create a C promang in an AIX System to read JPG files but when it read just the first 4 bytes when it found a DLE character (^P) doesn't read anymore. I using fread...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
1
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.