B
Bill Cunningham
I thought I would post this code. It seems to do what I want it to but I
thought I would have it critiqued. I use C89 but I think that maybe some of
the code maybe misplaced. For example, the fopen probably should be under
the strtod's shouldn't it ?
/*code C89 */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 6) {
puts("print usage error");
exit(EXIT_FAILURE);
}
FILE *fp;
char *error;
double a, b, c, d;
if ((fp = fopen(argv[5], "a")) == NULL)
perror(error);
a = strtod(argv[1], NULL);
b = strtod(argv[2], NULL);
c = strtod(argv[3], NULL);
d = strtod(argv[4], NULL);
fprintf(fp, "%.2f\t%.2f\t%.2f\t%.2f\n", a, b, c, d);
if ((fclose(fp)) == EOF)
perror(error);
return 0;
}
Thanks all.
Bill
thought I would have it critiqued. I use C89 but I think that maybe some of
the code maybe misplaced. For example, the fopen probably should be under
the strtod's shouldn't it ?
/*code C89 */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 6) {
puts("print usage error");
exit(EXIT_FAILURE);
}
FILE *fp;
char *error;
double a, b, c, d;
if ((fp = fopen(argv[5], "a")) == NULL)
perror(error);
a = strtod(argv[1], NULL);
b = strtod(argv[2], NULL);
c = strtod(argv[3], NULL);
d = strtod(argv[4], NULL);
fprintf(fp, "%.2f\t%.2f\t%.2f\t%.2f\n", a, b, c, d);
if ((fclose(fp)) == EOF)
perror(error);
return 0;
}
Thanks all.
Bill