matmatmat
May 19th, 2009, 04:44 PM
I'm trying to make a simple todo list program/thingy, I am using getopt to recognise options (eg '-a hello' where hello is the option (optarg?):
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]){
FILE *f;
int optchar;
while (optchar = getopt(argc, argv, "a:") != -1){
switch (optchar){
case 'a':
printf(optarg);
printf("case 'a'\n");
break;
}
if (optchar == "a"){
printf("if \"a\"");
}
if (optchar == 'a'){
printf("if 'a'");
}
}
}
when run nothing is outputted?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]){
FILE *f;
int optchar;
while (optchar = getopt(argc, argv, "a:") != -1){
switch (optchar){
case 'a':
printf(optarg);
printf("case 'a'\n");
break;
}
if (optchar == "a"){
printf("if \"a\"");
}
if (optchar == 'a'){
printf("if 'a'");
}
}
}
when run nothing is outputted?