forked from schedutron/CPAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upper.c
39 lines (32 loc) · 747 Bytes
/
upper.c
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
#include <math.h>
#include <stdio.h>
#include <ctype.h>
char *uppercase(char *string){
char *s = string;
while(*s){
*s = toupper((unsigned char) *s);
s++;
}
return string;
}
int main(){
char string[5] = "hEllo";
printf("%s\n", uppercase(string));
return 0;
}
#include "Python.h"
static PyObject *upper_uppercase(PyObject *self, PyObject *args){
char *orig_str;
PyObject *retval;
if(!PyArg_ParseTuple(args, "s", &orig_str))
return NULL;
retval = (PyObject*)Py_BuildValue("s", uppercase(orig_str));
return retval;
}
static PyMethodDef upperMethods[] =
{
{"to_uppercase", upper_uppercase, METH_VARARGS}
};
void initupper(){
Py_InitModule("upper", upperMethods);
}