![]() |
problem in file handling
Hi,
I am writing a program to extract names of all the classes in a particular directory. I have to search all the files in a directoy for the same. The program compiles well, but problem occurs while running it. It says 'can't open a file XX' and 'not enough memory'. I am using Turbo C. Please help me to know where I am doing wrong. The code is as below: Code:
#include <dirent.h> |
Re: problem in file handling
First your BUFF_SIZE is too small. In 16 bit DOS the file names are 8 characters and the file extensions are 3 characters so you have 8 + 3 = 9 plus the '.' = 10 plus the end of string character = 11. So that would mean the BUFF_SIZE should be at least 11. However I would set this much higher.
Also you are searching a directory then opening every file for reading, then scanning through the file for the string "class". However you will probably run into problems because the directory you are using may have binary files (.obj, .exe). You should probably only be looking at .h and .c .cpp files. Jim |
Re: problem in file handling
thanks jim
|
Re: problem in file handling
Is there any command to check the extension of a file in C?
|
Re: problem in file handling
Search from the end of the string for a dot, then strcmp the text after that point.
|
| All times are GMT +5.5. The time now is 12:31. |