Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 임베디드
- System.out
- Music player
- IntelliJ IDEA
- 뮤직 플레이어
- 깃허브 코파일럿
- SQL
- C언어 #코딩 #클래스 #구조체 #함수포인터 #포인터
- Java
- github copilot
- 깃허브
- 안드로이드스튜디오
- 기능대회
- C++
- vsC
- 프로그래밍
- C
- Hello World!
- Object-Oriented-C
- Scanner
- rust
- C-Class
- Visual Studio Code
- OOP
- eclipes
- android studio
- c언어
Archives
- Today
- Total
선우의 코딩일지
C ) C 언어로 JAVA Systm.out.println 비슷하게 따라해보기! 본문
오늘은 함수포인터를 사용해서 C 의 출력문을 비슷하게 구현 해보았다.
먼저 main.h 에 이렇게 소스코드를 작성한다.
#include <stdarg.h>
#ifndef _MAIN_H
#define _MAIN_H
#define null NULL
typedef enum{false, true} boolean;
typedef char *String;
void println(const String format, ...) {
va_list ap;
char buf[4096];
va_start(ap, format);
vsprintf(buf, format, ap);
va_end(ap);
fprintf(stdout, "%s\n", buf);
}
#pragma pack(push, 1)
typedef struct _System{
struct _OUT_{
void (*println)(const String, ...);
}out;
}Sys;
#pragma pack(pop)
Sys System = {println};
#endif
메인문을 아래와 같이 작성한다.
#include <stdio.h>
#include "main.h"
int main(void){
int a = 2;
double b = 0.12;
String str = "Hello World!";
System.out.println("Hello World!");
System.out.println("%d %lf", a, b);
System.out.println(str);
return 0;
}
출력
더보기
Hello World!
2 0.12
Hello World!
이렇게 println 을 구현 할 수있다.
'C' 카테고리의 다른 글
C) C언어로 자바 입출력 따라하기! (4) | 2022.09.18 |
---|---|
C) 여러 C 파일 한번에 컴파일 하는법! (0) | 2022.09.14 |
C) 2022 지방 기능경기대회 공업전자기기 3과제 풀이 (4) | 2022.08.22 |
C언어로 클래스 구현해보기 (1) | 2022.06.23 |
C) 1. Hello World! 출력하기 (0) | 2022.02.21 |
Comments