C 언어: sprintf 함수
C언어: 출력
/// 헤더파일
#include <stdio.h>
/// 함수원형
int sprintf (char * s, const char * format, ...)
/// 인자
const char * format, …: 문자열(과 문자열안의 서식 지정자에 관련된 값)
/// 반환값
성공시 반환값(return value): 출력 문자열의 문자 수(Byte 수)
오류시 반환값(return value): 음수
오류시 반환값(return value): 음수
/// 참고파일
헤더파일: stdio.h(연결)
헤더파일: stdio.h(연결)
소스파일: sprintf.c(연결)
reference
https://man7.org/linux/man-pages/man3/sprintf.3p.html
헤더파일: stdio.h(연결)
소스파일: sprintf.c(연결)
reference
https://man7.org/linux/man-pages/man3/sprintf.3p.html
/// 예제
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 | #include <stdio.h> #define BUFFER_SIZE 100 // 프로그램의 목적을 충분히 생각해봅시다. int main(void) { char Undefined_Way[BUFFER_SIZE]; char Defined_Way[BUFFER_SIZE]; char Mysterious[BUFFER_SIZE]; char Mysterious_Door[BUFFER_SIZE]; char Invisible_Teleporter[BUFFER_SIZE]; printf("------ Input Contents(to a memory)------\n"); printf("1th return value is %d\n", sprintf(Undefined_Way, "Nothing ---> (mysterious) ---> Something")); printf("2nd return value is %d\n", sprintf(Defined_Way, "Something ---> (mysterious boundary) ---> Something Different")); printf("3rd return value is %d\n", sprintf(Mysterious, "(mysterious)... (mysterious)... (mysterious)")); printf("4th return value is %d\n", sprintf(Mysterious_Door, "It's subtle, I could call it mysterious door")); printf("5th return value is %d\n", sprintf(Invisible_Teleporter, "It seems like as if invisible teleporter is right there")); printf("\n"); printf("------ Output Contents ------\n"); printf("%s", Undefined_Way); printf("\n"); printf("%s", Defined_Way); printf("\n"); printf("%s", Mysterious); printf("\n"); printf("%s", Mysterious_Door); printf("\n"); printf("%s", Invisible_Teleporter); printf("\n"); return 0; } | cs |
* 실행환경: Linux(5.7.6-x86_64-linode136)
* 컴파일러: gcc (Ubuntu 6.5.0-2ubuntu1~14.04.1) 6.5.0 20181026
- 당신을 응원합니다. -
댓글
댓글 쓰기