Write your question here.
1 2
|
After compile and implementing this code, result file only print 0.0000
why this phenomenon occur?
|
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc, char **argv){
FILE *fs, *fr, *res;
char *cr, *cs;
int row, column, i, j, file;
int IN=0;
double **data;
double temp;
cr = calloc(100, sizeof(char));
cs = calloc(100, sizeof(char));
res = fopen("channel res.txt","w");
for(i=0;i<argc-1;i++){
cr = *++argv;
sprintf(cs, "wc -l %s", cr);
fs = popen(cs, "r");
fscanf(fs, "%d", &row);
fclose(fs);
sprintf(cs, "wc -w %s", cr);
fs = popen(cs, "r");
fscanf(fs, "%d", &column);
fclose(fs);
column /= row;
data = (double **)malloc(row*sizeof(double *));
for(i=0;i<row;i++){
data[i] = (double *)malloc(column*sizeof(double));
}
fr = fopen(*argv, "r");
for(i=0;i<column;i++){
fscanf(fr, "%s", cr);
}
for(i=1;i<row;i++){
for(j=0;j<column;j++){
fscanf(fr, "%f", &temp);
printf("%f", temp);
data[i][j] = temp;
}
}
for(i=1;i<row;i++){
fprintf(res, "%f\t", data[i][1]);
fprintf(res, "%f", data[i][2]+IN);
fprintf(res, "\n");
}
IN = data[row-1][2];
fclose(fr);
}
}