Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 1st, 2007, 11:39 PM
Authorized User
Join Date: Jul 2007
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem while file read

 I think it is very silly, but i couldnt trace out the problem.
 I am trying to read 3 lines from file using fgets, then using fseek i m placing the pointer back one line.
 But after that when i do fgets i m not getting the complete line.Instead first 3 charecters are missing.

My code looks like

    for(i = 0; i < 3; i++)

    cnt = strlen(strBuf);
    fgets(strBuf,500,fpInFileNext); // now strBuf contains line with
                                         3 missing charecters.

What may be the problem?????????

Reply With Quote
  #2 (permalink)  
Old November 5th, 2007, 05:46 AM
Authorized User
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts

Hmm. How about just rewinding like:


I think the problem comes from new-line character (\r\n in Windows, \n in *nix) so you need to rewind past those also. I'm not sure where the third character comes from (too little coffeiine, can't think straight). If you are writing portable code you propably need to do some evil precompilter thingy:

#if _WIN32_

Or something like that.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
File read problem... john20 .NET Framework 2.0 4 September 9th, 2008 12:18 PM
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
how to read file vivekkumar_23 Java Basics 1 April 3rd, 2006 10:03 AM
How to Read from INI file alen Pro VB 6 2 September 3rd, 2004 06:34 AM
can't read file nikolaosk BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 July 28th, 2003 04:54 AM

All times are GMT -4. The time now is 01:03 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.