namereq

カンマごとに区切り、float型の2次元配列

Jun 28th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void)
  6. {
  7.     char PARAM_DATA_CHAR[100][1001]={
  8.         "0",
  9.         "0,-1.65,-5.67,-11,-16.33,-20.35,-22,-20.31,-15.79,-9.25,-1.5,6.5,14.25,20.79,25.31,27,25.52,21.64,16.04,9.63,2.99",
  10.         "0,-0.83,-2.83,-5.5,-8.17,-10.17,-11,-8.83,-4.16,1.66,7.72,13.24,17.82,20.86,22,20.81,17.83,13.79,9.06,4.15,-0.69",
  11.         "0",
  12.         "0,-0.04,-0.1,-0.16,-0.2,-0.22,-0.218,-0.212,-0.204,-0.193,-0.181,-0.168,-0.154,-0.139,-0.125,-0.11,-0.096,-0.083",
  13.         "0,-0.05,-0.14,-0.23,-0.31,-0.38,-0.45,-0.51,-0.56,-0.6,-0.63,-0.66,-0.69,-0.704,-0.72,-0.732,-0.74,-0.746,-0.749",
  14.         "0",
  15.         "0",
  16.         "0",
  17.         "1",
  18.         "0,0,0,0,0,0,0,0.18,0.46,0.73,0.92,1,1,1,1,1,1,1,1,1,0.93,0.79,0.62,0.43,0.27,0.13,0.03",
  19.         "0",
  20.         "0,-0.38,-1.29,-2.5,-3.71,-4.62,-5,-3.68,-0.46,3.47,7.3,10.38,12.34,13,13,13,13,13,13,11.9,9.21,5.94,2.75",
  21.         "0,0.1,0.34,0.71,1.14,1.58,2,2.38,2.65,2.82,2.92,2.97,2.99,3,3,3,3,3,3,2.91,2.69,2.38,2.02",
  22.         "0",
  23.         "0,-0.38,-1.29,-2.5,-3.71,-4.62,-5,-3.16,1.31,6.77,12.09,16.36,19.08,20,20,20,20,20,20,18.38,14.45,9.64",
  24.         "0,0.15,0.52,1,1.48,1.85,2,1.93,1.75,1.53,1.32,1.15,1.04,1,1,1,1,1,1,0.93,0.79,0.62,0.43,0.27,0.13,0.03",
  25.         "0,0,0,0,0,0,0,5.27,17.09,30.67,42.7,47.89,49.65,50,50,49.46,47.65,44.84,38.1,29.01,18.8,9.42,2.69"
  26.     };
  27.  
  28.     /* この配列をカンマごとに区切り、float型の2次元配列 */
  29.     float PARAM_DATA_FLOAT[100][1001] = {'\0'};
  30.     int i,j;
  31.     char *ptr;
  32.    
  33.     for(i=0;i<100;i++){
  34.         j=0;
  35.         ptr = strtok(PARAM_DATA_CHAR[i],",");
  36.         while(ptr != NULL){
  37.             PARAM_DATA_FLOAT[i][j++] = (float)atof(ptr);
  38.             ptr = strtok(NULL, ",");
  39.         }
  40.     }
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment