do{학습}while

c) fprintf() 본문

C & C++/c언어 표준함수

c) fprintf()

하이오야이 2024. 5. 27. 10:24

기능 요약

특정한 스트림에 일련의 데이터를 특정한 형식에 맞추어 파일에 입력

헤더파일

#include <stdio.h> //c++: <cstdio>

원형

int fprintf(FILE* stream, const char* format, ...);

주의 사항

예시 코드

#include <stdio.h>
int main() {
  FILE* fp = fopen("output.txt", "w");
  int integer = 123;
  char character = 'c';
  char string[] = "hello, world";
  int* pointer = &integer;
  double pi = 3.141592;

  fprintf(fp, "integer : (decimal) %d (octal) %o \\n", integer, integer);

  fprintf(fp, "character : %c \\n", character);

  fprintf(fp, "string : %s \\n", string);

  fprintf(fp, "pointer addr : %p \\n", pointer);

  fprintf(fp, "floating point : %e // %f \\n", pi, pi);

  fprintf(fp, "percent symbol : %% \\n");

  fclose(fp);
  
  return 0;
}

'C & C++ > c언어 표준함수' 카테고리의 다른 글

c) memcmp()  (0) 2024.05.27
c) sscanf()  (0) 2024.05.27
c) sprintf()  (0) 2024.05.27
c) fscanf()  (0) 2024.05.27
c) strdup()  (0) 2024.05.27