•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 375,231 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,195 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 309 | Replies: 6 | Solved
![]() |
•
•
Join Date: May 2008
Location: Mumbai, India
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
I want to read files and folder names from directories.
I have used the following code.
But the problem is that in the output the file name gets truncated.(See the output below)
=====
OUTPUT
=====
ABCABC~1.CPP
CURREN~1.EXE
CURREN~1.OBJ
============
The actual naes of the files are:
abcabcd.cpp
currentfolder.exe
currentfolder.obj
I would like to read the files as their original names....but I am unable to do so..
Please help!!
I have used the following code.
But the problem is that in the output the file name gets truncated.(See the output below)
C++ Syntax (Toggle Plain Text)
#include <dirent.h> #include <stdio.h> #include<conio.h> void main(void) { clrscr(); DIR *d; struct dirent *dir; d = opendir("."); if (d) { while ((dir = readdir(d)) != NULL) { printf("%s\n", dir->d_name); } closedir(d); } getch(); }
=====
OUTPUT
=====
ABCABC~1.CPP
CURREN~1.EXE
CURREN~1.OBJ
============
The actual naes of the files are:
abcabcd.cpp
currentfolder.exe
currentfolder.obj
I would like to read the files as their original names....but I am unable to do so..
Please help!!
Last edited by harsh2327 : May 10th, 2008 at 4:11 am.
It's because your crusty old Turbo C (which is like a decade out of date) doesn't understand the long filenames of your nice new OS (which is it, XP or Vista?).
Get a compiler which is good for this millenium, and compatible with the win32 API. A popular choice would be.
http://www.codeblocks.org/
But there are many high quality and FREE compilers available today, there is no excuse for sticking with the old stuff.
http://www.thefreecountry.com/compilers/cpp.shtml
Oh, and void main is wrong.
http://c-faq.com/ansi/maindecl.html
Get a compiler which is good for this millenium, and compatible with the win32 API. A popular choice would be.
http://www.codeblocks.org/
But there are many high quality and FREE compilers available today, there is no excuse for sticking with the old stuff.
http://www.thefreecountry.com/compilers/cpp.shtml
Oh, and void main is wrong.
http://c-faq.com/ansi/maindecl.html
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,556
Reputation:
Rep Power: 8
Solved Threads: 157
Actually, main DOES return a value. Never mind what you teacher told you or what Turbo thinks is normal, main returns an int. So use
If you are switching compilers, you might want to look at the findfirst() and findnext() functions
int main(void) and return 0;
If you are switching compilers, you might want to look at the findfirst() and findnext() functions
Last edited by niek_e : May 10th, 2008 at 8:06 am.
- On vacation -
Cheers
Cheers
> But why void main() is wrong
Did you bother to read the FAQ I posted?
Remember, programming at the limits of "what your current compiler will let you get away with" is no substitute for actually learning the language properly. All that implementation specific stuff will just cause you pain and suffering when you change compilers (and you will, many times).
Learning C is hard enough first time around without having to unlearn a bunch of compiler specific crap each time you change compilers. It sucked badly enough I resolved to only suffer such an experience only once. Now, I wander freely from one compiler to another and never miss a beat.
Did you bother to read the FAQ I posted?
Remember, programming at the limits of "what your current compiler will let you get away with" is no substitute for actually learning the language properly. All that implementation specific stuff will just cause you pain and suffering when you change compilers (and you will, many times).
Learning C is hard enough first time around without having to unlearn a bunch of compiler specific crap each time you change compilers. It sucked badly enough I resolved to only suffer such an experience only once. Now, I wander freely from one compiler to another and never miss a beat.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
Similar Threads
- project plz who can help me (C++)
- Open In New Window Php (PHP)
- Setting an array and reading in a txt file backwards (C++)
- who can help me in c++ project (C++)
- need help with a project (Shell Scripting)
- Virus Of Death - Help Needed! (Viruses, Spyware and other Nasties)
- only a couple of hours to go... (C++)
- I've got Trojan.Holax... is this bad? (Viruses, Spyware and other Nasties)
- not-a-virusadware (Viruses, Spyware and other Nasties)
Other Threads in the C Forum
- Previous Thread: Timing in C addon
- Next Thread: Validating Algorithms



Linear Mode