121_pdfsam_cs2022 - C:\> myprogram -x file1.txt...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Command-line arguments Command line arguments Command line arguments are passed as parameters to main() Full prototype of main: int main(int argc, char *argv[]) argc contains the number of command line arguments argv is an array of strings, one per command line argument e.g. for the command line above: argc = 4 argv[0]: “myprogram” argv[1]: “-x” argv[2]: “file1.txt” argv[3]: “file2.txt”a
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C:\> myprogram -x file1.txt file2.txt Command line arguments example #include <stdio.h> int main(int argc, char *argv) { int j; for(j=0; j<argc; j++) printf(%d %s\n, j, argv[j]); return 0; } C:\> program 12 -x test.txt 0 program 1 12 2 -x 3 test.text 3 Rules on Arrays int A[256], x; Declaration A[x]=. ..; Assignment (... =) A[x]; Take value...
View Full Document

Page1 / 3

121_pdfsam_cs2022 - C:\> myprogram -x file1.txt...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online