![]() |
|
#1
|
|||
|
|||
Opening a Binary FileHi,
My program is suppose to scan the directory, and count the number of files in it. The number of files in the direcotry should be appended to the name of the output file which can be selected by the user. After that, it is suppose to read the first 512 bytes of the first file in the direcoty according to a certain format. (the files are image files output of a microscope and they have 512 b header that contains the information about that specific image.) after the program scans and counts the number of directories, the pointer is put at the beginning of the directory, then it skips "." and " .. " and start by reading the byte 16 of the first file. I used seekg to put the pointer at byte 16. The tellg(), however gives back a value of -1. When i checked to see if the file opens properly or not using fail(), i got the error message, showing that the file has not been opened corectly. How can i know what is going wrong here? here is the the corresponding code for this part: CPP / C++ / C Code:
Thanks |
|||
|
#2
|
|||
|
|||
|
Quote:
There is no way that I can tell you why the file failed to open. You can get clues from your own program. Are you sure that you are trying to open the right file? Put in a line to show the file name. Something like the following: CPP / C++ / C Code:
If the file name is correct, does the file exist in the directory where your executable is? Regards, Dave |
|
#3
|
||||
|
||||
|
Hm, I remember this problem from another thread....
I only suggested the fail thing, but then I failed to answer your next question. Unfortunatelly, what I wanted to suggest was something like Dave already did Print the exact path to your file as you have it in your program (obtained through argv). Maybe it's not what you would expect (I'm thinking something like "c:\bla\bla", and then your filename, instead of "c:\bla\bla\" and then your filename - I'm only suggesting this because it happened to me ;-) ) So, please get back to us when you did it. Best regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#4
|
|||
|
|||
|
I have already tried to print out the name of the file that is supposed to be opened. It seems to be fine. I mean it prints the correct file name.
I do not compeltely understand what you mean by defining the path of the file. The program is suppose to go through the files in a (sub)directory one by one. It asks for the name of the directory, and the direcoty that contains the files is in the same directory as the program. do i need to specify the path of the directory in the ifstream ? something like : CPP / C++ / C Code:
Thank you |
|
#5
|
|||
|
|||
|
well, i actually tried
CPP / C++ / C Code:
Since it gives back the name of the file that is supposed to be read correctly, does not that mean the program has already located the file properly? thanks |
|
#6
|
|||
|
|||
|
Quote:
I am sorry but i do not quite follow you here. would you please explain... thank you |
|
#7
|
||||
|
||||
|
Quote:
I'm sorry I didn't answer very promptly, but when you posted it was 5-6 A.M. in my country. I was sleeping like a baby I hope you didn't literrally try this: CPP / C++ / C Code:
but, rather like this: CPP / C++ / C Code:
Observe the double "\\"(that's Windows) Of course, this kind of concatenation will not work under C (you'll get something about adding 2 pointers). It works with VC CStrings, though You' can do something with std:string and Insert, I don't mean to bore you... However, since it is in a (sub)directory of your application's directory, you still need something like: CPP / C++ / C Code:
Quote:
Does it print "SubDirectoryName\FileName"? BTW, I'm away for the weekend (Motivational Weekend ), so I hope you solve this....Best of luck, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#8
|
|||
|
|||
|
My Problem was resolved
Thank you ![]() |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 11:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
| Binary file: hitting eof too soon? | Alotau | C++ Forum | 20 | 18-May-2004 16:36 |
| Re: Programming Techniques | WaltP | C Programming Language | 0 | 10-Mar-2004 00:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The