B
Bill Cunningham
This simple little program takes from stdin and writes to stdout. No
other streams are involved. Why am I segmentation faulting? I am guessing it
has something to do with the argc==0 part of the program but I don't know
how I should change it.
All characters on each line should begin with an '+' otherwise the
characters aren't printed or in this case an error is triggered.
Bill#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
if (argc == 0) {
fprintf(stderr, "parsing usage error\n");
return 1;
}
if (*argv[1] == '+') {
puts("good + found\n");
return 0;
} else {
if (*argv[1] != '+') {
fputs("error + not found\n", stderr);
return 1;
}
return 0;
}
return 0;
}
other streams are involved. Why am I segmentation faulting? I am guessing it
has something to do with the argc==0 part of the program but I don't know
how I should change it.
All characters on each line should begin with an '+' otherwise the
characters aren't printed or in this case an error is triggered.
Bill#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
if (argc == 0) {
fprintf(stderr, "parsing usage error\n");
return 1;
}
if (*argv[1] == '+') {
puts("good + found\n");
return 0;
} else {
if (*argv[1] != '+') {
fputs("error + not found\n", stderr);
return 1;
}
return 0;
}
return 0;
}