Hello algorism,
I want to divide the first column by the number of data points, i. Suppose whn you run the program it shows the number of data point on screen, ref. line 68. I am confused of how to substitute '?' by i in line 61.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX 10000
int main(int argc, char *argv[])
{
FILE *fs, *ft;
char *foldpoint, line[MAX];
int i, low, high, n[MAX], size,sum;
double fp,v;
if (argc != 5) {
puts("Improper number of arguments\nType rawfilename foldedfilename foldingpoint velocity");
exit(0);
}
fs = fopen(argv[1], "r");
if (fs == NULL) {
puts("Cannot open source file");
exit(0);
}
ft = fopen(argv[2], "w");
if (ft == NULL) {
puts("Cannot open target file");
exit(0);
}
foldpoint = argv[3];
sscanf(foldpoint, "%lf", &fp);
printf("Folding point= %lf\n", fp);
sscanf(argv[4], "%lf", &v);
printf("Drive velocity= %lf\n", v);
i = 0;
while (fgets(line, sizeof(line), fs)) {
sscanf(line, "%d", &n[i]);
i++;
if (i == (int)fp) {
printf("%lf is %s", fp, line);
}
}
size = i;
if (fp == (int)fp) {
low = (int)fp;
high = low;
}
else {
low = (int)fp;
high = low + 1;
}
sum=0;
low--;
high--;
i = 0;
while (low >= 0 && high < size) {
/* sscanf(line,"%d %d", &i, &n[i] ); */
fprintf(ft, "%lf %d\n", (2*i)*v/?, (n[low]+n[high]));
/* printf("%d %d\n", i, (n[low]-n[high])*(n[low]-n[high])); */
sum=sum+((n[low]-n[high])*(n[low]-n[high]));
low--;
high++;
i++;
}
printf("data points= %d\n", i);
printf("Sum of least sqaures= %d\n", sum);
fclose(fs);
fclose(ft);
return 0;
}
Thanks again.
Regads, raja.