B
Bill Cunningham
This function code compiles and I have inserted comments. I get this
warning.
p.c:12:25: warning: multi-line string literals are deprecated
I see this is where the fprintfs are but I don't see the error. This is
kind of an old compiler. gcc-3-x-x.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
double ema(double ma1[], double ma2[], double ma3[], unsigned int days)
{
if (days == 0 || days == 1) {
fprintf(stderr, "must have 2 or more days\n");
return -1;
}
if (ma1 == 0 && ma2 == 0 && ma3 == 0) {
fprintf(stderr, "must enter some value for moving average
parameter(s)\n"); //something wrong here compiler says.
return -1;
}
double ema = 2 / (days + 1);
if (ma1 != 0 && ma2 == 0 && ma3 == 0) {
double result = days/(*ma1 / ema);
printf("%.2f\n", result); // I will probably take these prints out
after testing.
exit(errno); //Is this how to use errno? First time trying.
}
if (ma1 != 0 && ma2 != 0 && ma3 == 0) {
double result1, result2;
result1 = days/(*ma1 / ema);
result2 = days/(*ma2 / ema);
printf("%.2f %.2f\n", result1, result2);
exit(errno);
}
if (ma1 != 0 && ma2 != 0 && ma3 != 0) {
double result1, result2, result3;
result1 = days/(*ma1 / ema);
result2 = days/(*ma2 / ema);
result3 = days/(*ma3 / ema);
printf("%.2f %.2f %.2f\n", result1, result2, result3);
exit(errno);
}
return 0;
}
I how this is more acceptable. Like I said it compiles into object code
to be linked with main.
B
warning.
p.c:12:25: warning: multi-line string literals are deprecated
I see this is where the fprintfs are but I don't see the error. This is
kind of an old compiler. gcc-3-x-x.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
double ema(double ma1[], double ma2[], double ma3[], unsigned int days)
{
if (days == 0 || days == 1) {
fprintf(stderr, "must have 2 or more days\n");
return -1;
}
if (ma1 == 0 && ma2 == 0 && ma3 == 0) {
fprintf(stderr, "must enter some value for moving average
parameter(s)\n"); //something wrong here compiler says.
return -1;
}
double ema = 2 / (days + 1);
if (ma1 != 0 && ma2 == 0 && ma3 == 0) {
double result = days/(*ma1 / ema);
printf("%.2f\n", result); // I will probably take these prints out
after testing.
exit(errno); //Is this how to use errno? First time trying.
}
if (ma1 != 0 && ma2 != 0 && ma3 == 0) {
double result1, result2;
result1 = days/(*ma1 / ema);
result2 = days/(*ma2 / ema);
printf("%.2f %.2f\n", result1, result2);
exit(errno);
}
if (ma1 != 0 && ma2 != 0 && ma3 != 0) {
double result1, result2, result3;
result1 = days/(*ma1 / ema);
result2 = days/(*ma2 / ema);
result3 = days/(*ma3 / ema);
printf("%.2f %.2f %.2f\n", result1, result2, result3);
exit(errno);
}
return 0;
}
I how this is more acceptable. Like I said it compiles into object code
to be linked with main.
B