2

In java, there are FileChannels where I can read from file channel. I can also set the position in the channel where I want to start reading.

Any similar functions in C++/C?

Will
  • 4,585
  • 1
  • 26
  • 48
user1785771
  • 487
  • 2
  • 7
  • 18
  • In the C++ world we call this a "file stream". – leemes Nov 04 '12 at 15:58
  • A channel is different than a stream. We have streams in java @Will – user1785771 Nov 04 '12 at 16:08
  • @user1785771: I was just trying to clarify the situation in case some people didn't know that Java has both FileInputStream and FileChannel. I added the link so that people could see what interface you wanted. http://stackoverflow.com/q/1605332/1353098 – Will Nov 04 '12 at 16:26

2 Answers2

6

Please look into C++'s ifstream::seekg() and ifstream::tellg(). Also in C: ftell() and fseek() functions in <stdio.h>

Aniket Inge
  • 25,375
  • 5
  • 50
  • 78
0

if you want a solution with C programming

If you want to read from position X then you can use fread() up to the (X-1) and then reuse fread() or fgets() or fgetc() to read from the position X

How to read a text file upto certain position in C?

Community
  • 1
  • 1
MOHAMED
  • 41,599
  • 58
  • 163
  • 268