B
Bill Cunningham
This code absolutely will not compile. I have looked and looked at it
and can't see and error. This is what I have and the compiler's complaints.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
double radians, degrees;
radians = degrees = 0.0;
if (argc == 1 || argc > 3) {
fputs("Usage error\n", stderr); // not user friendly I know
exit(0);
} // but for my purpose fine.
if (argv[1] != "r" || argv[1] != "d") {
fputs(" Usage error\n Must be d for degrees or r for
radians\n", stderr);
exit(0);
}
if (argv[1] == "r") {
degrees = strtod(argv[2], NULL);
radians = degrees * 3.1415 / 180;
printf("%.4f\n", radians);
return 0;
}
if (argv[1] == "d") {
radians = strtod(argv[2], NULL);
degrees = radians * 180 / 3.1415;
printf("%.4f\n", degrees);
return 0;
}
return 0;
}
p.c: In function `main':
p.c:13: error: missing terminating " character
p.c:14: error: stray '\' in program
p.c:14: error: syntax error before "n"
p.c:14: error: missing terminating " character
The \n looks fine everywhere to me.
Bill
and can't see and error. This is what I have and the compiler's complaints.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
double radians, degrees;
radians = degrees = 0.0;
if (argc == 1 || argc > 3) {
fputs("Usage error\n", stderr); // not user friendly I know
exit(0);
} // but for my purpose fine.
if (argv[1] != "r" || argv[1] != "d") {
fputs(" Usage error\n Must be d for degrees or r for
radians\n", stderr);
exit(0);
}
if (argv[1] == "r") {
degrees = strtod(argv[2], NULL);
radians = degrees * 3.1415 / 180;
printf("%.4f\n", radians);
return 0;
}
if (argv[1] == "d") {
radians = strtod(argv[2], NULL);
degrees = radians * 180 / 3.1415;
printf("%.4f\n", degrees);
return 0;
}
return 0;
}
p.c: In function `main':
p.c:13: error: missing terminating " character
p.c:14: error: stray '\' in program
p.c:14: error: syntax error before "n"
p.c:14: error: missing terminating " character
The \n looks fine everywhere to me.
Bill