Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
challoc
/* test sort an array */ #include <stdio.h> #include <string.h> /* challoc works like malloc, but from static area. Do not free. calling with sz = 0 will free everything and start over */ void *challoc(int sz){ // set aside a static buffer static char mem[BUFSIZ]; static int idx, last; if (!(sz)) return(idx=0, NULL); // allocate from static area last = idx, idx += sz; if(idx > BUFSIZ) return NULL; else return &mem[last];} char *st4dup(char *s){ return strcpy(challoc(strlen(s)+1), s);} int main(int argc, char **argv, char** env){ char *j = st4dup("hello"); if(j) puts(j); char *p = st4dup("there"); if(p) puts(p); return 0; }
run
|
edit
|
history
|
help
0
Hello world.c
IndiSelSort
est
String copy
Don't ignore warnings
FUNCION strstr()
19_1_7
Basic String Compression in C
Euclides MIRAR
strcmp