Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Python.h> //Python dev module
- // Define a function
- static PyObject* CExten_CCat(PyObject* self, PyObject* args){
- const char* file_path;
- FILE* fd;
- char chunk[128];
- //parsing the arguments (only if needed)
- if(!PyArg_ParseTuple(args, "s", &file_path)){
- return NULL; //send error to the python interpreter
- }
- if((fd = fopen(file_path,"r")) < 0){
- return NULL;
- }
- while((fgets(chunk,sizeof(chunk),(FILE*)fd)) != NULL){
- printf("%s",chunk);
- }
- printf("\n");
- fclose(fd);
- Py_INCREF(Py_None);
- return Py_None;
- }
- static PyMethodDef CExten_methods[] = {
- //Python Func Name C Func Name Arg Count Description
- {"CCat", CExten_CCat, METH_VARARGS, NULL},
- {NULL,NULL,0,NULL} //ending sentinel
- };
- PyMODINIT_FUNC initCExten(void){
- PyObject *m;
- m = Py_InitModule("CExten",CExten_methods);
- if(m == NULL){
- return;
- }
- }
Add Comment
Please, Sign In to add comment