-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
50 lines (42 loc) · 1.32 KB
/
example.c
File metadata and controls
50 lines (42 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* File : example.c
* Based on the 'hurry' example at http://www.swig.org/tutorial.html
* This is compiled in Visual Studio 2019, 64-bit, for Windows.
* Environment vars:
* PYTHON_INCLUDE: blah\Python\Python39\include
* PYTHON_LIB: blah\Python\Python39\libs\python39.lib
* The 'example' project in example_dll.vcxproj generates example.dll which is copied to /_example.pyd.
* RunMe.py exercises _example.pyd.
* A custom build operation was created for example.i that runs ./swig.bat which has a command like: "C:\Program Files\SWIG\swigwin-4.0.2\swig.exe" -python -o example_wrap.c example.i
*
*/
#include <time.h>
#include <stdio.h>
double My_variable = 3.21;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t rawtime = 0;
time(&rawtime);
struct tm ltime = { 0 };
localtime_s(<ime, &rawtime);
static char result[52]; // it's ok to return the address of a static (not on the stack) buffer.
sprintf_s(
result,
sizeof(result),
"%04d-%02d-%02d %02d:%02d:%02d\n",
1900 + ltime.tm_year,
1 + ltime.tm_mon,
ltime.tm_mday,
ltime.tm_hour,
ltime.tm_min,
ltime.tm_sec
);
return result;
}