By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

reading using fread

P: 25
how do i read from a text file using fread
Sep 19 '06 #1
Share this Question
Share on Google+
3 Replies


Banfa
Expert Mod 5K+
P: 8,916
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

P: 25
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
P: 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.