update: userprog (tee, tsh, sleep, hex2bin)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
TARGET = hex2bin
|
||||
SRCS = hex2bin.c
|
||||
CC = gcc
|
||||
CFLAGS = -static -Wall
|
||||
|
||||
OUT_BIN ?= $(TARGET)
|
||||
|
||||
all: $(OUT_BIN)
|
||||
|
||||
$(OUT_BIN): $(SRCS)
|
||||
@echo " [CC] Compiling to $(OUT_BIN)..."
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// 사용법: echo "41 42 43" | hex2bin
|
||||
int main() {
|
||||
int byte;
|
||||
// 16진수(%x)로 정수를 읽어서
|
||||
while (scanf("%x", &byte) == 1) {
|
||||
// char(바이트) 형태로 stdout에 씀
|
||||
unsigned char c = (unsigned char)byte;
|
||||
fwrite(&c, 1, 1, stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user