Click here to Skip to main content
15,917,061 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Best way to display a progressbar for file copying Pin
l a u r e n25-Dec-03 13:17
l a u r e n25-Dec-03 13:17 
GeneralRe: Best way to display a progressbar for file copying Pin
PJ Arends25-Dec-03 13:29
professionalPJ Arends25-Dec-03 13:29 
GeneralRe: Best way to display a progressbar for file copying Pin
shultas25-Dec-03 14:04
shultas25-Dec-03 14:04 
GeneralRe: Best way to display a progressbar for file copying Pin
shultas25-Dec-03 14:13
shultas25-Dec-03 14:13 
GeneralRe: Best way to display a progressbar for file copying Pin
PJ Arends25-Dec-03 14:36
professionalPJ Arends25-Dec-03 14:36 
GeneralRe: Best way to display a progressbar for file copying Pin
shultas25-Dec-03 15:34
shultas25-Dec-03 15:34 
GeneralRe: Best way to display a progressbar for file copying Pin
PJ Arends25-Dec-03 16:03
professionalPJ Arends25-Dec-03 16:03 
GeneralBest way to read a text file Pin
shultas25-Dec-03 11:44
shultas25-Dec-03 11:44 
Hello again all.

I am wondering what the best way for me to read a text file would be in Visual C++ 6.0. I have some files (like log files) that are one line a piece, ending with a CR or CR/LF at the end of each line. Currently, I am using c, fopen/fgets. I have a couple of issues with the way I am doing it now.

1. I don't know the function to get the size of the file. I've got 4 books sitting around (and a couple normal C books), and have looked on the WEB and MSDN for hours trying to find the function to do this, with no avail Frown | :( The reason I need the filesize is because I am using a progress bar to let the user know the status. Currently, I am fread() over and over until the end of the file, counting each time I do that, then setting that as the max for the progress bar, then fseek() to the beginning of the file, and begin the normal processing (that takes a little time). So, the crap thing about this is that it literally has to read the file two times to do it's thing in order for me to get the progress bar going right. (This is because I don't know how to get the size of the file!)

2. I was trying to determine the size of the file during the while (fgets...!=NULL) {} loop. I was reading into variable "buf". I tried using strlen(buf) and adding that to a variable "totalBytes", but it is always off. It appears as though the CR/LF is throwing off the strlen.

So I am wondering first off, how would I determine the size of the file. And, while processing (with fgets() ), how do I know exactly how many bytes I've read in. Also, I am wondering if it is wiser to use CFile or something of that nature to read the file (if it would be faster?) Currently, it appears that the routines that I've tested out in CFile read the file in big chunks, not one line at a time like fgets(), so it makes it a little bit harder for me to parse the data. I would prefer to read one line at a time, this way I don't have to make these routines that have to save data over for the next pass in order to parse correctly.

Any help would be appreciated. I'm just starting out in VC++ and doing pretty much everything by reading all the text's on this site, plus a couple of books that I picked up, and MSDN's site. Lots and lots of searching. Most of the time I find what I need but sometimes a simple little thing like this (I did a lot of C programming in the past, but I just forgot most of the functions) takes a long time for me to find out!

Thanks all!
GeneralRe: Best way to read a text file Pin
PJ Arends25-Dec-03 12:04
professionalPJ Arends25-Dec-03 12:04 
Generaluse CStdioFile class Pin
abudu25-Dec-03 20:54
abudu25-Dec-03 20:54 
GeneralProblem How to get All files from a Folder Pin
xxtra25-Dec-03 8:53
xxtra25-Dec-03 8:53 
GeneralRe: Problem How to get All files from a Folder Pin
PJ Arends25-Dec-03 9:14
professionalPJ Arends25-Dec-03 9:14 
GeneralRe: Problem How to get All files from a Folder Pin
(Steven Hicks)n+125-Dec-03 9:18
(Steven Hicks)n+125-Dec-03 9:18 
GeneralDll Functions Name & parameters Pin
Ghasrfakhri25-Dec-03 6:32
Ghasrfakhri25-Dec-03 6:32 
GeneralRe: Dll Functions Name & parameters Pin
valikac25-Dec-03 7:02
valikac25-Dec-03 7:02 
GeneralRe: Dll Functions Name & parameters Pin
User 665825-Dec-03 7:03
User 665825-Dec-03 7:03 
GeneralRe: Dll Functions Name & parameters Pin
Sebastián Benítez25-Dec-03 7:53
Sebastián Benítez25-Dec-03 7:53 
GeneralProgress Bar Slowing Down Program Pin
shultas25-Dec-03 5:30
shultas25-Dec-03 5:30 
GeneralRe: Progress Bar Slowing Down Program Pin
PJ Arends25-Dec-03 9:21
professionalPJ Arends25-Dec-03 9:21 
GeneralRe: Progress Bar Slowing Down Program Pin
shultas25-Dec-03 12:34
shultas25-Dec-03 12:34 
GeneralRe: Progress Bar Slowing Down Program Pin
Michael Dunn25-Dec-03 19:20
sitebuilderMichael Dunn25-Dec-03 19:20 
Questionhow solve this debug erro? Pin
benben25-Dec-03 3:56
benben25-Dec-03 3:56 
AnswerRe: how solve this debug erro? Pin
Robert Kuster25-Dec-03 4:22
Robert Kuster25-Dec-03 4:22 
Generalthanks a lot Pin
benben28-Dec-03 20:31
benben28-Dec-03 20:31 
QuestionHow to detect network adapter status in windows2000/xp? Pin
hpudx24-Dec-03 22:02
hpudx24-Dec-03 22:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.