次の5つのファイルから構成されているルーレットの簡易的なゲームを作りたいのですが、gnuplot_i.cの24行目(▲▲で囲われた部分)の「NULLポインター'handle'を逆参照しています」というエラーが一向に解決できません。
また、デバッカーを実行すると、指定されたファイルが見つかりませんと表示され、ビルドエラーになってしまいます。プログラムがよく分からないので丁寧にご教授お願い致します。
ファイルは追加コメントに貼っておきます
投稿時に変な風に区切られてしまったのでここにgnuplot_i.cのコードを貼っておきます。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <stdarg.h>
#include"gnuplot_i.h"
#include"teigi.h"
#ifdef _WIN32
#include <windows.h>
#define popen _popen
#define pclose _pclose
#endif
//gnuplot_ctrl構造体を実装する
struct gnuplot_ctrl {
FILE* gnuplotPipe;
};
//Gnuplotを初期化するための関数
gnuplot_ctrl* gnuplot_init() {
gnuplot_ctrl *handle = malloc(sizeof(gnuplot_ctrl));
▲ handle->gnuplotPipe = _popen("gnuplot -persistent", "w"); ▲
return handle;
}
//Gnuplotを閉じるための関数
void gnuplot_close(gnuplot_ctrl* handle) {
if (handle) {
pclose(handle->gnuplotPipe);
free(handle);
}
}
//Gnuplotコマンドを送信するための関数
void gnuplot_cmd(gnuplot_ctrl* handle, const char* command, ...) {
va_list ap;
va_start(ap, command);
vfprintf(handle->gnuplotPipe, command, ap);
fprintf(handle->gnuplotPipe, "\n");
fflush(handle->gnuplotPipe);
va_end(ap);
}
//ルーレットを回すムービーを表示するための関数
void plotroulmovie(int result) {
gnuplot_ctrl* h = gnuplot_init();
if (!h) return;
gnuplot_cmd(h, "set xrange [0:36]");
gnuplot_cmd(h, "set yrange [0:1]");
gnuplot_cmd(h, "set title 'Roul Spin'");
char command[128];
sprintf_s(command, sizeof(command), "plot '-' using 1:2 with points pt 7 title 'Result: %d'", result);
gnuplot_cmd(h, command);
gnuplot_cmd(h, "%d %d", result, 1);
gnuplot_cmd(h, "e");
gnuplot_close(h);
}
回答1件
あなたの回答
tips
プレビュー