#include
#include
#define MAXSIZE 100
typedef struct stack{
int stk[MAXSIZE];
int top;
} STACK;
void Push(int x, STACK *s){
int num;
s->top ++;
printf("Push %d\n", s->top);
s->stk[s->top] = x;
return;
}
int Pop(STACK *s){
int num;
printf("Pop %d\n", s->top);
num = s->stk[s->top];
s->top --;
return num;
}
void Init(STACK *s){
s->top = -1;
printf("Init %d\n", s->top);
return;
}
int main(){
STACK *s = (STACK *)malloc(sizeof(STACK));
Init(s);
Push(1, s);
Push(2, s);
Push(3, s);
printf("%d\n", Pop(s));
printf("%d\n", Pop(s));
printf("%d\n", Pop(s));
}
2018/07/08
[c] Stack
2018/07/07
[c] learn-c.org
Welcome
Welcome to the learn-c.org free interactive C tutorial.Whether you are an experienced programmer or not, this website is intended for everyone who wishes to learn the C programming language.
There is no need to download anything - Just click on the chapter you wish to begin from, and follow the instructions. Good luck!
http://www.learn-c.org
2018/06/12
[python] text from url
import requests
import json
url = 'http://www.quotesondesign.com/wp-json/posts'
resp = requests.get(url)
# srting to Python data type
c_lst = json.loads(resp.text)
for txt in c_lst:
# unpacking
for key, value in txt.items():
print(key, ' : ', value)
2018/06/11
[python] json
import json
# Json String to variable
sample = {
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
# string to Json encoding with formatting
sample_json = json.dumps(sample, indent = 4)
print(sample_json)
print('')
# Decoding Json String to Python type
sample_structured_json = json.loads(sample_json)
print(sample_structured_json)
print('')
print(sample_structured_json['glossary']['title'])
print('')
for i in sample_structured_json['glossary']['GlossDiv']['GlossList']['GlossEntry']:
print(i)
2018/06/08
[python] binary data write to file
# binary data generation
bdata = bytes(range(0, 256))
# check length and data
print('size :', len(bdata), '\ndata : ', bdata)
# set offset and chunk size, get data size
offset = 0
chunk = 10
size = len(bdata)
# write to file and get size
with open('bfile.bin', 'wb') as bf:
while offset <= size:
bf.write(bdata[offset:offset+chunk])
offset += chunk
# check file
! cat bfile.bin
피드 구독하기:
글 (Atom)