stdio

Autres langues

Langue: ja

Version: 2001-12-26 (openSuse - 09/10/07)

Section: 3 (Bibliothèques de fonctions)

̾Á°

stdio - ɸ½àÆþ½ÐÎϥ饤¥Ö¥é¥ê´Ø¿ô

½ñ¼°

#include <stdio.h>

FILE *stdin;
FILE *stdout;
FILE *stderr;

ÀâÌÀ

ɸ½àÆþ½ÐÎϥ饤¥Ö¥é¥ê¤Ï¡¢´Êñ¤«¤Ä¸ú²Ì¤Î¤è¤¤¡¢ ¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤µ¤ì¤¿¥¹¥È¥ê¡¼¥àÆþ½ÐÎÏ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤òÄ󶡤¹¤ë¡£ ÆþÎϤȽÐÎϤÏÏÀÍý¥Ç¡¼¥¿¥¹¥È¥ê¡¼¥à¤Ë³ä¤êÉÕ¤±¤é¤ì¡¢ Æþ½ÐÎϤÎʪÍýŪ¤ÊÆÃħ¤Ï±£Ê䵤ì¤ë¡£ ¤³¤Î¥é¥¤¥Ö¥é¥ê¤Ë°¤¹¤ë´Ø¿ô¤È¥Þ¥¯¥í¤ò°Ê²¼¤Ëµó¤²¤ë¡£ ¤è¤ê¾Ü¤·¤¤¾ðÊó¤Ï¸Ä¡¹¤Î man ¥Ú¡¼¥¸¤«¤éÆÀ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£

¥Õ¥¡¥¤¥ë¤ò ¥ª¡¼¥×¥ó (open) ¤¹¤ë ¤³¤È¤Ë¤è¤Ã¤Æ¡¢ ¥¹¥È¥ê¡¼¥à¤Ï³°Éô¥Õ¥¡¥¤¥ë (Ä̾ï¤ÏʪÍý¥Ç¥Ð¥¤¥¹) ¤ËÏ¢·ë¤µ¤ì¤ë¡£ ¤³¤ÎÁàºî¤Ë¤Ï¿·¤·¤¯¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë¤³¤È¤â´Þ¤Þ¤ì¤ë¡£ ´û¸¤Î¥Õ¥¡¥¤¥ë¤ÈƱ¤¸Ì¾Á°¤Î¥Õ¥¡¥¤¥ë¤ò¿·¤¿¤Ëºî¤ë¤È¡¢ ¤â¤È¤Î¥Õ¥¡¥¤¥ë¤ÎÃæ¿È¤¬¼Î¤Æ¤é¤ì¤Æ¤·¤Þ¤¦¡£ ¥Õ¥¡¥¤¥ë¤¬°ÌÃÖ»ØÄê¥ê¥¯¥¨¥¹¥È¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë (¥Ç¥£¥¹¥¯¥Õ¥¡¥¤¥ë¤Ê¤É¤¬ÁêÅö¤¹¤ë¡£µÕ¤ÎÎã¤È¤·¤Æ¤ÏüËö¤¬µó¤²¤é¤ì¤ë) ¾ì¹ç¡¢ ¤½¤Î¥¹¥È¥ê¡¼¥à¤ËÏ¢·ë¤µ¤ì¤¿ ¥Õ¥¡¥¤¥ë°ÌÃֻؼ¨»Ò (file position indicator) ¤Ï¡¢Äɲå⡼¥É¤Ç³«¤«¤ì¤Ê¤¤¸Â¤ê¥Õ¥¡¥¤¥ë¤ÎÀèƬ (0 ¥Ð¥¤¥ÈÌÜ) ¤Ë°ÌÃÖ¤¹¤ë¡£ Äɲå⡼¥É¤ò»ÈÍѤ·¤¿¾ì¹ç¡¢ °ÌÃֻؼ¨»Ò¤ò¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤ËÃÖ¤«¤ì¤ë¤«ËöÈø¤ËÃÖ¤«¤ì¤ë¤«¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£ °ÌÃֻؼ¨»Ò¤Ï¡¢ °Ê¹ß¤ÎÆɤ߽ñ¤­¤ä°ÌÃÖ»ØÄê¥ê¥¯¥¨¥¹¥È¤Ë¤è¤Ã¤ÆÊѹ¹¤µ¤ì¤ë¡£ ¤¹¤Ù¤Æ¤ÎÆþÎϤϡ¢ fgetc(3) ´Ø¿ô¤ò¼¡¡¹¤Ë¸Æ¤Ó½Ð¤·¤Æʸ»ú¤òÆɤ߹þ¤ó¤À¤«¤Î¤è¤¦¤Ë¹Ô¤ï¤ì¤ë¡£ °ìÊý¤¹¤Ù¤Æ¤Î½ÐÎϤϡ¢ fputc(3) ´Ø¿ô¤ò¼¡¡¹¤Ë¸Æ¤Ó½Ð¤·¤Æʸ»ú¤ò½ñ¤­¹þ¤ó¤À¤«¤Î¤è¤¦¤Ë¹Ô¤ï¤ì¤ë¡£

¥Õ¥¡¥¤¥ë¤ò ¥¯¥í¡¼¥º (close) ¤¹¤ë ¤³¤È¤Ë¤è¤Ã¤Æ¡¢¤½¤Î¥Õ¥¡¥¤¥ë¤Ï¥¹¥È¥ê¡¼¥à¤«¤éÀÚ¤êÎ¥¤µ¤ì¤ë¡£ ½ÐÎÏ¥¹¥È¥ê¡¼¥à¤Ï¡¢¤½¤Î¥¹¥È¥ê¡¼¥à¤¬¥Õ¥¡¥¤¥ë¤«¤éÀÚ¤êÎ¥¤µ¤ì¤ëÁ°¤Ë¥Õ¥é¥Ã¥·¥å¤µ¤ì¤ë (½ñ¤­¹þ¤Þ¤ì¤Æ¤¤¤Ê¤¤¤¹¤Ù¤Æ¤Î¥Ð¥Ã¥Õ¥¡¤ÎÆâÍƤ¬¥Û¥¹¥È´Ä¶­¤ËžÁ÷¤µ¤ì¤ë)¡£ FILE ¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤ÎÃͤϡ¢ ¥Õ¥¡¥¤¥ë¤òÊĤ¸¤¿¸å¤Ç¤ÏÉÔ³ÎÄê¤Ë¤Ê¤ë (¥´¥ß¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦)¡£

¥Õ¥¡¥¤¥ë¤Ï¤½¤Î¸å (Ʊ¤¸¤Þ¤¿¤ÏÊÌ¤Î¥×¥í¥°¥é¥à¤Ë¤è¤Ã¤Æ) ºÆ¤Ó¥ª¡¼¥×¥ó¤µ¤ì¤ë¤³¤È¤â¤¢¤ê¡¢ ¤½¤ÎÆâÍƤ¬½¤Àµ¤µ¤ì¤¿¤êÊѹ¹¤µ¤ì¤¿¤ê¤¹¤ë (¤½¤Î¥Õ¥¡¥¤¥ë¤ÇÀèƬ¤Ø¤Î°ÌÃÖ°ÜÆ°¤¬²Äǽ¤Ç¤¢¤ì¤Ð)¡£ main ´Ø¿ô¤¬¤â¤È¤Î¸Æ¤Ó½Ð¤·Â¦¤ËÊ֤俤ꡢ exit(3) ´Ø¿ô¤¬¸Æ¤Ð¤ì¤¿¾ì¹ç¡¢ ¥×¥í¥°¥é¥à¤Î½ªÎ»¤ÎÁ°¤Ë ¸½ºß³«¤¤¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¥Õ¥¡¥¤¥ë¤ÏÊĤ¸¤é¤ì¤ë (¤½¤Î·ë²Ì¡¢¤¹¤Ù¤Æ¤Î½ÐÎÏ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥é¥Ã¥·¥å¤µ¤ì¤ë)¡£ ¥×¥í¥°¥é¥à¤ÎÄä»ß¤Ë abort(3) ¤Î¤è¤¦¤Ê¾¤ÎÊýË¡¤òÍѤ¤¤¿¾ì¹ç¤Ë¤Ï¡¢ ¥Õ¥¡¥¤¥ë¤¬Àµ¤·¤¯ÊĤ¸¤é¤ì¤ëÊݾڤϤʤ¤¡£

¥×¥í¥°¥é¥à¤Îµ¯Æ°»þ¤Ë 3 ¸Ä¤Î¥Æ¥­¥¹¥È¥¹¥È¥ê¡¼¥à¤¬Í½¤áÄêµÁ¤µ¤ì¤Æ¤ª¤ê¡¢ ¤½¤ì¤é¤ÏÌÀ¼¨Åª¤Ë³«¤¯É¬Íפ¬¤Ê¤¤¡£ --- ɸ½àÆþÎÏ (standard input) (Ä̾ï¤ÎÆþÎϤòÆɤ߼è¤ë¤Î¤Ë»È¤¦)¡¢--- ɸ½à½ÐÎÏ (standard output) (Ä̾ï¤Î½ÐÎϤò½ñ¤­¹þ¤à¤Î¤Ë»È¤¦)¡¢ ɸ½à¥¨¥é¡¼½ÐÎÏ (standard error) (¿ÇÃǽÐÎϤò½ñ¤­¹þ¤à¤Î¤Ë»È¤¦) ¤Ç¤¢¤ë¡£ ¤³¤ì¤é¤Î¥¹¥È¥ê¡¼¥à¤Ï stdin, stdout, stderr ¤Èû½Ì¤·¤Æɽ¸½¤µ¤ì¤ë¡£ ¥ª¡¼¥×¥ó¤µ¤ì¤¿¤È¤­¤Ë¤Ï¡¢ ɸ½à¥¨¥é¡¼¥¹¥È¥ê¡¼¥à¤Ï ´°Á´¤Ë¤Ï¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤µ¤ì¤Æ¤¤¤Ê¤¤¡£ ɸ½àÆþÎÏ¥¹¥È¥ê¡¼¥à¤Èɸ½à½ÐÎÏ¥¹¥È¥ê¡¼¥à¤Ï¡¢ ¥¹¥È¥ê¡¼¥à¤¬¥¤¥ó¥¿¥é¥¯¥Æ¥£¥Ö¤Ê¥Ç¥Ð¥¤¥¹¤ò»²¾È¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢ ´°Á´¤Ë¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤µ¤ì¤Æ¤¤¤ë¡£

üËö¥Ç¥Ð¥¤¥¹¤ò»²¾È¤¹¤ë½ÐÎÏ¥¹¥È¥ê¡¼¥à¤Ï¡¢ ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¾ï¤Ë¹Ôñ°Ì¤Ç¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤µ¤ì¤Æ¤¤¤ë¡£ ¤¿¤À¤·¤½¤Î¤è¤¦¤Ê¥¹¥È¥ê¡¼¥à¤Ë¤ª¤±¤ë¥Ð¥Ã¥Õ¥¡Æâ¤Î½ÐÎϤϡ¢ üËö¥Ç¥Ð¥¤¥¹¤ò»²¾È¤·¤Æ¤¤¤ëÆþÎÏ¥¹¥È¥ê¡¼¥à¤«¤é¤ÎÆɤ߹þ¤ß¤¬¤¢¤ë¤¿¤Ó¤Ë¡¢ ¼«Æ°Åª¤Ë½ñ¤­¹þ¤Þ¤ì¤ë¡£ ½ÐÎÏüËö¤Ë¹Ô¤Î°ìÉô¤ò½ñ¤­¹þ¤ó¤À¸å¤ÇÂçÎ̤η׻»¤ò¹Ô¤¦¾ì¹ç¡¢ ½ÐÎϤ¬É½¼¨¤µ¤ì¤ë¤è¤¦¤Ë¡¢·×»»¤Ë¼è¤ê¤«¤«¤ëÁ°¤Ëɸ½à½ÐÎϤËÂФ·¤Æ fflush(3) ¤ò¼Â¹Ô¤¹¤ëɬÍפ¬¤¢¤ë¡£

stdio ¥é¥¤¥Ö¥é¥ê¤Ï libc ¥é¥¤¥Ö¥é¥ê¤Î°ìÉô¤Ç¤¢¤ê¡¢¥ë¡¼¥Á¥ó¤Ï ¥³¥ó¥Ñ¥¤¥é¡¼ cc(1) ¤È pc(1) ¤Ë¤è¤Ã¤ÆɬÍפʻþ¤Ë¼«Æ°Åª¤ËÆɤ߹þ¤Þ¤ì¤ë¡£ ¸å½Ò¤¹¤ë man ¥Ú¡¼¥¸Ãæ¤Î½ñ¼°¤ÎÀá¤Ë¤Ï¡¢ ¤É¤Î¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë¤ò»ÈÍѤ·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤«¡¢ ¤½¤Î´Ø¿ô¤Î¥³¥ó¥Ñ¥¤¥é¡¼Àë¸À¤Ï¤É¤Î¤è¤¦¤Ê¤â¤Î¤«¡¢ ¤É¤Î¤è¤¦¤Ê³°ÉôÊÑ¿ô¤¬´Ø·¸¤¹¤ë¤Î¤«¤¬¼¨¤µ¤ì¤Æ¤¤¤ë¡£

BUFSIZ, EOF, FILENAME_MAX, FOPEN_MAX, L_cuserid, L_ctermid, L_tmpnam, NULL, SEEK_END, SEEK_SET, SEE_CUR, TMP_MAX, clearerr, feof, ferror, fileno, getc, getchar, putc, putchar, stderr, stdin, stdout ¤Ï¥Þ¥¯¥í¤È¤·¤ÆÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£ ¤³¤ì¤é¤Î̾Á°¤Ï¡¢¸½ºß¤ÎÄêµÁ¤ò #undef ¤Çºï½ü¤·¤Ê¤¤¸Â¤ê¡¢ºÆÍøÍѤ¹¤ë¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£ ¥Þ¥¯¥í´Ø¿ô¤Î´Ø¿ôÈǤȤ·¤Æ¡¢ feof, ferror, clearerr, fileno, getc, getchar, putc, putchar ¤¬¤¢¤ë¡£ ¥Þ¥¯¥í¤ÎÄêµÁ¤¬ÌÀ¼¨Åª¤Ë¾Ãµî¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢ ¤³¤ì¤é¤ò»ÈÍѤ¹¤ë¤³¤È¤Ë¤Ê¤ë¤À¤í¤¦¡£

´Ø¿ô¤Î¥ê¥¹¥È

´Ø¿ô
ÀâÌÀ
clearerr
¥¹¥È¥ê¡¼¥à¤Î¾õÂ֤γÎǧ¤È¥ê¥»¥Ã¥È
fclose
¥¹¥È¥ê¡¼¥à¤ò¥¯¥í¡¼¥º¤¹¤ë
fdopen
¥¹¥È¥ê¡¼¥à¤ò¥ª¡¼¥×¥ó¤¹¤ë´Ø¿ô
feof
¥¹¥È¥ê¡¼¥à¤Î¾õÂ֤γÎǧ¤È¥ê¥»¥Ã¥È
ferror
¥¹¥È¥ê¡¼¥à¤Î¾õÂ֤γÎǧ¤È¥ê¥»¥Ã¥È
fflush
¥¹¥È¥ê¡¼¥à¤ò¥Õ¥é¥Ã¥·¥å¤¹¤ë
fgetc
¼¡¤Îʸ»ú¤Þ¤¿¤Ï¸ì¤òÆþÎÏ¥¹¥È¥ê¡¼¥à¤«¤é³ÍÆÀ¤¹¤ë
fgetpos
¥¹¥È¥ê¡¼¥à¤Î°ÌÃÖ¤ò¼èÆÀ¤¹¤ë
fgets
¥¹¥È¥ê¡¼¥à¤«¤é¹Ô¤ò¼èÆÀ¤¹¤ë
fileno
°ú¤­¿ô¤Ç¤¢¤ë¥¹¥È¥ê¡¼¥à¤ÎÀ°¿ôÃͤΥǥ£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹
fopen
¥¹¥È¥ê¡¼¥à¤ò¥ª¡¼¥×¥ó¤¹¤ë´Ø¿ô
fprintf
À°·Á¤µ¤ì¤¿½ÐÎÏÊÑ´¹´Ø¿ô
fpurge
¥¹¥È¥ê¡¼¥à¤ò¥Õ¥é¥Ã¥·¥å¤¹¤ë
fputc
ʸ»ú¤Þ¤¿¤Ï¸ì¤ò¥¹¥È¥ê¡¼¥à¤Ë½ÐÎϤ¹¤ë
fputs
¹Ô¤ò¥¹¥È¥ê¡¼¥à¤Ë½ÐÎϤ¹¤ë
fread
¥Ð¥¤¥Ê¥ê¡¼¥¹¥È¥ê¡¼¥àÆþ½ÐÎÏ
freopen
¥¹¥È¥ê¡¼¥à¤ò¥ª¡¼¥×¥ó¤¹¤ë´Ø¿ô
fscanf
½ñ¼°ÉÕ¤­ÆþÎÏÊÑ´¹
fseek
¥¹¥È¥ê¡¼¥à¤Î°ÌÃֻؼ¨»Ò¤ò°ÜÆ°¤¹¤ë
fsetpos
¥¹¥È¥ê¡¼¥à¤Î°ÌÃֻؼ¨»Ò¤ò°ÜÆ°¤¹¤ë
ftell
¥¹¥È¥ê¡¼¥à¤Î°ÌÃÖ¤ò¼èÆÀ¤¹¤ë
fwrite
¥Ð¥¤¥Ê¥ê¡¼¥¹¥È¥ê¡¼¥àÆþ½ÐÎÏ
getc
¼¡¤Îʸ»ú¤Þ¤¿¤Ï¸ì¤òÆþÎÏ¥¹¥È¥ê¡¼¥à¤«¤é¼èÆÀ¤¹¤ë
getchar
¼¡¤Îʸ»ú¤Þ¤¿¤Ï¸ì¤òÆþÎÏ¥¹¥È¥ê¡¼¥à¤«¤é¼èÆÀ¤¹¤ë
gets
¹Ô¤òÆþÎÏ¥¹¥È¥ê¡¼¥à¤«¤é¼èÆÀ¤¹¤ë
getw
¼¡¤Îʸ»ú¤Þ¤¿¤Ï¸ì¤òÆþÎÏ¥¹¥È¥ê¡¼¥à¤«¤é¼èÆÀ¤¹¤ë
mktemp
¾¤È½Å¤Ê¤é¤Ê¤¤¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë̾¤òºî¤ë
perror
¥·¥¹¥Æ¥à¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
printf
½ñ¼°ÉÕ¤­½ÐÎÏÊÑ´¹
putc
ʸ»ú¤Þ¤¿¤Ï¸ì¤ò¥¹¥È¥ê¡¼¥à¤Ë½ÐÎϤ¹¤ë
putchar
ʸ»ú¤Þ¤¿¤Ï¸ì¤ò¥¹¥È¥ê¡¼¥à¤Ë½ÐÎϤ¹¤ë
puts
¹Ô¤ò¥¹¥È¥ê¡¼¥à¤Ë½ÐÎϤ¹¤ë
putw
ʸ»ú¤Þ¤¿¤Ï¸ì¤ò¥¹¥È¥ê¡¼¥à¤Ë½ÐÎϤ¹¤ë
remove
¥Ç¥£¥ì¥¯¥È¥ê¥¨¥ó¥È¥ê¤òºï½ü¤¹¤ë
rewind
¥¹¥È¥ê¡¼¥à¤Î°ÌÃֻؼ¨»Ò¤ò°ÜÆ°¤¹¤ë
scanf
½ñ¼°ÉÕ¤­ÆþÎÏÊÑ´¹
setbuf
¥¹¥È¥ê¡¼¥à¤Î¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤ÎÁàºî
setbuffer
¥¹¥È¥ê¡¼¥à¤Î¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤ÎÁàºî
setlinebuf
¥¹¥È¥ê¡¼¥à¤Î¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤ÎÁàºî
setvbuf
¥¹¥È¥ê¡¼¥à¤Î¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤ÎÁàºî
sprintf
½ñ¼°ÉÕ¤­½ÐÎÏÊÑ´¹
sscanf
½ñ¼°ÉÕ¤­ÆþÎÏÊÑ´¹
strerror
¥·¥¹¥Æ¥à¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
sys_errlist
¥·¥¹¥Æ¥à¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
sys_nerr
¥·¥¹¥Æ¥à¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
tempnam
¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤ÎÁàºî
tmpfile
¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤ÎÁàºî
tmpnam
¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤ÎÁàºî
ungetc
ÆþÎÏ¥¹¥È¥ê¡¼¥à¤Ø 1 ʸ»úÌ᤹¡£
vfprintf
½ñ¼°ÉÕ¤­½ÐÎÏÊÑ´¹
vfscanf
½ñ¼°ÉÕ¤­ÆþÎÏÊÑ´¹
vprintf
½ñ¼°ÉÕ¤­½ÐÎÏÊÑ´¹
vscanf
½ñ¼°ÉÕ¤­ÆþÎÏÊÑ´¹
vsprintf
½ñ¼°ÉÕ¤­½ÐÎÏÊÑ´¹
vsscanf
½ñ¼°ÉÕ¤­ÆþÎÏÊÑ´¹

½àµò

stdio ¥é¥¤¥Ö¥é¥ê¤Ï C89 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£

´ØÏ¢¹àÌÜ

close(2), open(2), read(2), write(2), stdout(3), unlocked_stdio(3)