471,850 Members | 1,024 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

reading using fread

how do i read from a text file using fread
Sep 19 '06 #1
3 11818
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

Post your reply

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

Similar topics

19 posts views Thread by Lionel B | last post: by
2 posts views Thread by JS | last post: by
3 posts views Thread by syntax | last post: by
4 posts views Thread by Matthew Crema | last post: by
21 posts views Thread by EdUarDo | last post: by
6 posts views Thread by arne.muller | last post: by
3 posts views Thread by juleigha27 | last post: by
16 posts views Thread by Jm.GlezdeRueda | last post: by
4 posts views Thread by Giacomo | last post: by
6 posts views Thread by jcasique.torres | last post: by
aboka
reply views Thread by aboka | last post: by

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.