Command-line wildcards and argument types in C. For the corrected program below executed as: cmd> sample "*.c", what will be printed (assume DOS/Turbo C style where the shell does not expand wildcards)? /* sample.c (corrected) / #include<stdio.h> int main(int argc, char argv[]) { int i; for(i = 1; i < argc; i++) printf("%s ", argv[i]); return 0; }
Correct Answer: .c
Introduction / Context: The question clarifies two ideas: (1) main should receive a character pointer vector for argv; and (2) on DOS/Turbo C style environments, the command processor typically does not expand wildcards, so "*.c" is passed literally to the program unless a runtime library performs special expansion.
Given Data / Assumptions:
- Program signature corrected to int main(int argc, char *argv[]).
- Command line: sample "*.c".
- Environment assumption: wildcard is not expanded by the shell (unlike typical Unix shells).
Concept / Approach: With no wildcard expansion, argv[1] receives the literal characters *.c (without quotes, since the shell strips quotes). The loop prints each argument from i=1 to argc-1, so the output is a single line containing *.c.
Step-by-Step Solution:
argc >= 2 because one user argument exists. argv[1] == "*.c" with the quotes removed by the command processor. printf prints the literal *.c followed by newline.Verification / Alternative check: On Unix-like systems, the shell would expand "*.c" to matching filenames before launching the program. Under the DOS assumption, that expansion does not occur; the program sees the literal string.
Why Other Options Are Wrong:
- "*.c": Quotes are not retained.
- sample *.c: argv[0] (program) is not printed by the loop.
- List of files: Requires shell-side expansion, not assumed here.
- Compilation error: The corrected signature compiles.
Common Pitfalls: Forgetting that argument quoting behavior differs between DOS and Unix shells; also, using int* argv is a type error for %s printing.
Final Answer: *.c