In this tutorial, I will show you something very simple without using the ncurses library.
It is about using arguments in the command line.
Create a file default.c and complete it with the source code below:
1 2 3 4 5 6 7 8 9 10 | #include <stdio.h> int main(int argc, char **argv) { printf("default command \n"); printf("argc = %d\n", argc); for(int i = 0; i < argc; i++) { printf("argv[%d] = %s\n", i, argv[i]); } return 0; } |
Use the gcc command tool to build this source code:
1 | [mythcat@fedora cmdsLinux]$ gcc -o default default.c |
You can test the new command named default, like this:
1 2 3 4 5 6 7 | [mythcat@fedora cmdsLinux]$ ./default test1 test2 test3 default command argc = 4 argv[0] = ./default argv[1] = test1 argv[2] = test2 argv[3] = test3 |