Re: sh?tpile of errors
"Martin Ambuhl" <mambuhl@earthl ink.netwrote in message
news:TIGdnRoOIZ myVgnVnZ2dnUVZ_ oTinZ2d@earthli nk.com...
Now I see that strchr is going to be needed here. I'm using headers too
I've never used.
Bill
"Martin Ambuhl" <mambuhl@earthl ink.netwrote in message
news:TIGdnRoOIZ myVgnVnZ2dnUVZ_ oTinZ2d@earthli nk.com...
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h /* mha: added */
/* mha: removed silly macro */
>
int main(int argc, char *argv[])
{
if (argc != 4) {
fputs("print usage error\n", stderr);
exit(EXIT_FAILU RE);
}
if (isalpha(argv[1]) || isalpha(argv[2])) {
fputs("name is 3rd arg\n", stderr);
exit(EXIT_FAILU RE);
}
double x, y;
FILE *fp;
x = strtod(argv[1], NULL);
y = strtod(argv[2], NULL);
if (!(fp = fopen(argv[3], "a"))) { /* mha: fixed parenthesis
error */
fputs("fopen error\n", stderr);
exit(EXIT_FAILU RE);
}
fprintf(fp, "%.2f %.2f\n", x, y); /* mha: fixed multiple errors
in arguments to fprintf.
Since there is no way to be
sure what you are trying to
do, I had to guess. */
if (fclose(fp) == EOF) { /* mha: fixed parenthesis error and
completely bogus comparison to
NULL */
fputs("fclose error\n", stderr);
exit(EXIT_FAILU RE);
}
return 0;
}
#include <stdlib.h>
#include <ctype.h /* mha: added */
/* mha: removed silly macro */
>
int main(int argc, char *argv[])
{
if (argc != 4) {
fputs("print usage error\n", stderr);
exit(EXIT_FAILU RE);
}
if (isalpha(argv[1]) || isalpha(argv[2])) {
fputs("name is 3rd arg\n", stderr);
exit(EXIT_FAILU RE);
}
double x, y;
FILE *fp;
x = strtod(argv[1], NULL);
y = strtod(argv[2], NULL);
if (!(fp = fopen(argv[3], "a"))) { /* mha: fixed parenthesis
error */
fputs("fopen error\n", stderr);
exit(EXIT_FAILU RE);
}
fprintf(fp, "%.2f %.2f\n", x, y); /* mha: fixed multiple errors
in arguments to fprintf.
Since there is no way to be
sure what you are trying to
do, I had to guess. */
if (fclose(fp) == EOF) { /* mha: fixed parenthesis error and
completely bogus comparison to
NULL */
fputs("fclose error\n", stderr);
exit(EXIT_FAILU RE);
}
return 0;
}
I've never used.
Bill
Comment