Untitled
unknown
c_cpp
21 days ago
1.2 kB
6
Indexable
Never
#include <stdio.h> #include <string.h> #include <math.h> #include "806_Grade_Calculator.h" double CharToDouble(char *s){ int len = 0; while( *(s+len) != '\0' ){ len++; } len--; int ans = 0; // printf("---\ns = %s, len = %d\n---\n", s, len); for(int i=0; i<len; i++){ //printf(" *(s+i) = %c\n", *(s+i) ); //printf(" -> %d\n", (*(s+i) - '0') ); ans += ( *(s+i) - '0' ) * pow(10, len - 1 - i); } //printf(" ans = %d\n", ans); return (double) ans; } void CalcVariance(char *csv_text, double *mean_array, double *variance_array, int row, int column){ /* 1. Using strtok to split the string 2. Using CharToDouble to convert string to double 3. Calculating mean and varianc */ printf("csv_text =\n%s\n", csv_text); double score[column][row]; char *s1; char *s2; s1 = strtok(csv_text, "\n"); for(int i=0; i<row; i++){ printf("s1 = %s\n", s1); for(int j=0; j<column; j++){ s2 = strtok(csv_text, ","); printf("s2 = %s\n", s2); score[j][i] = CharToDouble(s2); s2 = strtok(NULL, ","); } s1 = strtok(NULL, "\n"); } }
Leave a Comment