From the course: Advanced C Programming: Optimize Performance and Efficiency
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Solution: Reading the command line - C Tutorial
From the course: Advanced C Programming: Optimize Performance and Efficiency
Solution: Reading the command line
(upbeat music) - [Instructor] For my solution. I use an if statement of line five to ensure that at least one argument was typed. You could have made this decision as equals to or less than. That works also. When no arguments are typed then line seven displays an error message and line eight exits the program with a return value of one. At line 11, the file name argument or whatever the first argument was, is displayed. You don't really need to do any checking to confirm that it's a valid file name. That would be nice, but most programs don't bother. They simply try to open whatever was typed, and if it can't be opened, then, well, it can't be opened.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.