I started using wiringPi for UART for the raspberry pi and my attiny2313.
I don't want to write ten 1 character different .c code.
I know that with python I can use sys.argv[x]. How do I do it with wiringPi (I'm new to wiringPi)
Cheers
Code: Select all
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i, p1, p2;
for (i=0; i<argc; i++) printf("arg%d is %s\n", i, argv[i]);
if (argc>1) p1 = atoi(argv[1]); else p1=-1;
if (argc>2) p2 = atoi(argv[2]); else p2=-2;
printf("p1=%d p2=%d\n", p1, p2);
return 0;
}
A better answer is to learn about libpopt ! It should be one of the first libraries new C programmers are introduced to .joan wrote:Save the following as args.c and compile with gcc -o args args.c
.
A bit late for me I'm afraid. Depends on what you are doing - for throw away programs I'd do the above. For anything more serious I use getopt. This is the first I have heard of popt, Can't keep abreast of all these new fangled libraries.PeterO wrote:A better answer is to learn about libpopt ! It should be one of the first libraries new C programmers are introduced to .joan wrote:Save the following as args.c and compile with gcc -o args args.c
.
install libpopt-dev and read man 3 popt
PeterO