"C"의 두 판 사이의 차이

ph
이동: 둘러보기, 검색
(새 문서: ==Read/write float binary== [https://stackoverflow.com/q/1422817/766330 How to read a float from binary file in C?] / [https://stackoverflow.com/a/1422854/766330 answer] <pre> void w...)
 
잔글
1번째 줄: 1번째 줄:
 +
==gets없이 공백 포함한 문자열 scanf==
 +
scanf ("%[^\n]%*c", pt);
 +
설명이 너~무 좋아서 그냥 모두 복사해옴. [https://stackoverflow.com/questions/6282198/reading-string-from-input-with-space-character 출처]
 +
The <c>[]</c> is the ''scanset'' character. <c>[^\n]</c> tells that while the input is not a newline ('\n') take input. Then with the <c>%*c</c> it reads the newline character from the input buffer (which is not read), and the <c>*</c> indicates that this read in input is discarded (''assignment suppression''), as you do not need it, and this newline in the buffer does not create any problem for next inputs that you might take.
 +
 
==Read/write float binary==
 
==Read/write float binary==
 
[https://stackoverflow.com/q/1422817/766330 How to read a float from binary file in C?] / [https://stackoverflow.com/a/1422854/766330 answer]
 
[https://stackoverflow.com/q/1422817/766330 How to read a float from binary file in C?] / [https://stackoverflow.com/a/1422854/766330 answer]

2017년 11월 6일 (월) 23:35 판

gets없이 공백 포함한 문자열 scanf

scanf ("%[^\n]%*c", pt);

설명이 너~무 좋아서 그냥 모두 복사해옴. 출처 The [] is the scanset character. [^\n] tells that while the input is not a newline ('\n') take input. Then with the %*c it reads the newline character from the input buffer (which is not read), and the * indicates that this read in input is discarded (assignment suppression), as you do not need it, and this newline in the buffer does not create any problem for next inputs that you might take.

Read/write float binary

How to read a float from binary file in C? / answer

void writefloat(float v, FILE *f) {
  fwrite((void*)(&v), sizeof(v), 1, f);
}

float readfloat(FILE *f) {
  float v;
  fread((void*)(&v), sizeof(v), 1, f);
  return v;
}