デフォルト値を割り当てるかどうかを決定する関数を作成しました (フラグが存在しない場合はデフォルト値を割り当て、フラグが存在する場合はユーザーが渡す値を割り当てます)。そして、関数を文字列でテストして、正しい数値が得られるかどうかを確認しようとしています。テストを実行しようとすると、「Segmentation Fault」が発生し続けます。コンパイルはできますが、テストが機能しません。:(
これが私のヘッダーファイルです:
#ifndef COMMANDLINE_H
#define COMMANDLINE_H
#include "data.h"
#include <stdio.h>
struct point eye;
/* The variable listed above is a global variable */
void eye_flag(int arg_list, char *array[]);
#endif
これが私の実装ファイルです:
#include <stdio.h>
#include "commandline.h"
#include "data.h"
#include "string.h"
/* Used global variables for struct point eye */
void eye_flag(int arg_list, char *array[])
{
   eye.x = 0.0;
   eye.y = 0.0;
   eye.z = -14.0;
   /* The values listed above for struct point eye are the default values. */
   for (int i = 0; i <= arg_list; i++)
   {
      if (strcmp(array[i], "-eye") == 0)
      {
         sscanf(array[i+1], "%lf", &eye.x);
         sscanf(array[i+2], "%lf", &eye.y);
         sscanf(array[i+3], "%lf", &eye.z);
      }
   }
}
そして、ここに私のテストケースがあります:
#include "commandline.h"
#include "checkit.h"
#include <stdio.h>
void eye_tests(void)
{
   char *arg_eye[6] = {"a.out", "sphere.in.txt", "-eye", "2.4", "3.5", "6.7"};
   eye_flag(6, arg_eye);
   checkit_double(eye.x, 2.4);
   checkit_double(eye.y, 3.5);
   checkit_double(eye.z, 6.7);
   char *arg_eye2[2] = {"a.out", "sphere.in.txt"};
   eye_flag(2, arg_eye2);
   checkit_double(eye.x, 0.0);
   checkit_double(eye.y, 0.0);
   checkit_double(eye.z, -14.0);
}
int main()
{
   eye_tests();
   return 0;
}