The code to recursively plow a directory tree presented in last week’s Lesson could be improved upon. Primarily, it relies upon the .. shortcut to jump back to the parent directory. This method works only some of the time.
Continue reading
Category Archives: Lesson
Directory Spelunking
Exploring a folder tree — I mean directory tree — is a procedure found in many file and media utilities. From an original directory, you scan the list of files looking for a subdirectory. When it’s found, you open it and recursively continue the scan.
Continue reading
Pulling a Directory
O how well I remember DOS. It wasn’t Unix, but it cribbed from Unix heavily. One of the popular DOS commands was DIR, which was like the shell command ls, but more primitive. A typical DOS directory listing looked something like this:
Continue reading
Directory Entry File Types
Not every file listed in a directory is the same. Some entries represent other directories, subdirectories, for example. To determine which entries are mere mortal files and which are directories, you must examine the file type.
Continue reading
Reading a Directory
I’m refusing to call it a “folder.” That nonsense gained popularity with the Macintosh and then Windows. Before then, it was a directory, a list of files stored on media. Special C language functions are available to read and manipulate directories, which helps your programs manage files and do other fun file stuff.
Continue reading
What Evil Lurks in a Header File . . . ?
As a beginner, your first exposure to a header file is most likely <stdio.h>, which you understand is necessary for some reason. Then you may confuse the header file with the library, which is common but wrong. And you may even dabble with your own header files. Beyond that, few tutorials bother to mention any necessary details about what should go into a header file and when it’s necessary . . . until now.
Continue reading
Eliminating the Blanks
My solution for this month’s Exercise generated a list of duplicated letters in a string. The list also includes blank lines. It’s possible to prevent the blank lines from being displayed, but to do so requires extra programming kung fu.
Continue reading
Ten C Programming Mistakes
I’m certain that more than 10 C programming mistakes are common, but for some reason people enjoy lists with 10 items. My list of Ten C Programming Mistakes isn’t a top-ten list, so nothing is ranked. These are just a collection (cut off at 10) of the problems and issues I find most frequently when coding in the C language.
Continue reading
To Split a String in C
Have you ever heard a programmer mock the C language? Recently, a C# programmer informed me that C was okay, but “you can’t even split a string in C in less than 20 lines of code.”
Challenge accepted!
Continue reading
Stupid main() Function Tricks
The main() function is the first C language function you learn to write. It’s required. And you probably know that it has arguments, which are culled from the command prompt and made available to the program. So what stupid stuff can you do with main()?
Continue reading