1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <stdio.h>
#include <stdlib.h>
///////////////////////////////////
// //
// You may copy/adapt this code. //
// //
///////////////////////////////////
int main(int argc, char* argv[]) {
// argc is the number of command-line arguments, *including* the
// command itself.
//
// ./264echo "the neemotode has < 200 neurons (sp?)"
// ↑ ↑
// argv[0] argv[1]
//
// argv[0] == "./264echo"
// argv[1] == "the neemotode has < 200 neurons (sp?)"
if(argc == 2) {
printf("%s\n", argv[1]);
}
else {
fprintf(stderr, "Usage: %s STRING", argv[0]);
// Usage: ./264echo STRING
}
// stderr just means any error messages that you want to see on your
// terminal, even if you are redirecting the normal output to a file.
//
//
return EXIT_SUCCESS;
}
// Example: When we compile this, we will run the following:
// gcc -o 264echo 264echo.c
// ↑ ↑ ↑ ↑
// │ │ │ │
// arg[0] argv[2] argv[3] == "264echo.c"
// │
// argv[1] == "-o" … and so on
//
// argc == 4
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2019 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.