added 1.6

This commit is contained in:
ada-dmitry
2023-12-21 11:44:34 +03:00
parent 5bbe9fdf26
commit e405b960a7
16 changed files with 568 additions and 22 deletions
+48
View File
@@ -0,0 +1,48 @@
/*
* $gcc -Wall main.c -o main -ldl
* $./main sin\(x\) 1.62
* 0.998790
* $./main sin\(x\)*exp\(x\) 1.62
* 5.046975
*/
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#define BEGIN "#include <math.h>\ndouble func(double x){\nreturn "
#define END ";\n}\n"
#define MAKELIB "gcc -c -Wall func.c -o func.o && gcc -L. -shared func.o -o libfunc.so -lm"
int main(int argc, char *argv[])
{
void *handle;
double (*fun)(double);
char *error;
FILE *f;
f = fopen("func.c", "w");
fprintf(f, "%s%s%s", BEGIN, argv[1], END);
fclose(f);
system(MAKELIB);
handle = dlopen("./libfunc.so", RTLD_LAZY);
if (!handle)
{
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
dlerror();
fun = (double (*)(double))dlsym(handle, "func");
error = dlerror();
if (error != NULL)
{
fprintf(stderr, "%s\n", error);
exit(EXIT_FAILURE);
}
printf("%f\n", (*fun)(atof(argv[2])));
dlclose(handle);
exit(EXIT_SUCCESS);
}
+24 -12
View File
@@ -22,25 +22,37 @@ void show_grapgh()
new_term.c_lflag &= ~(ECHO | ICANON);
tcsetattr(STDIN_FILENO, TCSANOW, &new_term);
char func[100] = "x - x * x + 1349";
// char *gnuplotCommand = "gnuplot -persist -e \"plot sin(x)\" pause -1";
// system(gnuplotCommand);
// Подключение GNU Plot
FILE *gp = popen("gnuplot -persist", "w");
// FILE *gp = system("gnuplot -persist");
// if (gp == NULL)
// {
// printf("GNUerror\n");
// exit(3);
// }
// fprintf(gp, "set xrange [-500:500]\n");
// fprintf(gp, "set yrange [0:500]\n");
// fprintf(gp, "plot %s, 0\n", func);
// fflush(gp); // очищение буфера вывода
printf("set terminal wxt enhanced\n");
printf("plot sin(x)\n");
printf("pause mouse keypress\n");
// system("echo 'set term x11' | gnuplot -persist");
// system("set xrange [-500:500]\n set yrange [0:500]\n echo 'plot x - x * x + 1349'\n gnuplot -persist");
// system("exit\n");
// system("set yrange [0:500]\n | gnuplot -persist");
// system("echo 'plot x - x * x + 1349' | gnuplot -persist");
if (gp == NULL)
{
printf("GNUerror\n");
exit(3);
}
fprintf(gp, "set xrange [-500:500]\n");
fprintf(gp, "set yrange [0:500]\n");
fprintf(gp, "plot %s, 0\n", func);
fflush(gp); // очищение буфера вывода
sig_flag = 1;
printf("Нажмите любую клавишу, чтобы продолжить...\n");
getchar();
sig_flag = 0;
fprintf(gp, "exit\n");
// fprintf(gp, "exit\n");
tcsetattr(STDIN_FILENO, TCSANOW, &old_term);
return;
}
+5 -1
View File
@@ -18,6 +18,10 @@ int main()
pb = &b;
px = &x;
printf("set terminal wxt enhanced\n");
printf("plot sin(x)\n");
printf("pause mouse keypress\n");
struct sigaction sig_int, sig_tstp; // Инициализация структуры, отвечающей за обработку сигнала.
// Замена стандартного алгоритма на необходимый для вызова меню действий.
sig_int.sa_handler = ctrlc_handler;
@@ -38,7 +42,7 @@ int main()
return 1;
}
show_grapgh();
// show_grapgh();
input_diap();
if (*mth == 0)
Binary file not shown.