1¡¢fgets()º¯Êý
º¯ÊýÔÐÍ£ºchar*fgets(char *s, int size, FILE *stream);
º¯Êý¹¦ÄÜ£º´ÓÎļþÁ÷streamÖжÁÈ¡size×Ö½Ú´óСµÄÊý¾Ýµ½sËùÖ¸µÄÄÚ´æÖÐ(Êý ×éÃû»òÕßÖ¸Õë)
2¡¢fputs()º¯Êý
º¯ÊýÔÐÍ£ºint fputs(constchar *s, FILE *stream);
º¯Êý¹¦ÄÜ£º½«sËùÖ¸µÄÄÚ´æÖеÄÊý¾ÝÊä³öµ½ÎļþÁ÷ÖÐ
×¢Ò⣺fgets ºÍ fputs ´ÓÎļþÁ÷ stream ÖжÁдһÐÐÊý¾Ý;
puts ºÍ gets ´Ó±ê×¼ÊäÈëÊä³öÁ÷ÖжÁдһÐÐÊý¾Ý¡£
3¡¢gets()º¯Êý
º¯Êý¹¦ÄÜ£ºÊäÈë×Ö·û´®(¼üÅÌÊäÈë)
º¯ÊýÔÐÍ£ºgets(×Ö·ûÊý×éÃû) char *gets(char *s);
Ìص㣺¿ÉÒÔʶ±ð¿Õ¸ñ¡¢tabÖ®ÀàµÄ×Ö·û£¬²¢ÇÒ½«Æä±£´æÔÚÊý×éÖÐ
¾ÖÏÞ£º Ò»´ÎÖ»ÄÜÊäÈëÒ»¸ö×Ö·û´® »»¾ä»°Ëµ£¬Óöµ½»»Ðзû¾Í»á½áÊøÊäÈë(enter »Ø³µ¼ü)£¬'\0'ϵͳ»á×Ô¶¯ÔÚ»»Ðзû֮ǰ×Ô¶¯¼ÓÈë
×¢Ò⣺ scanf()ÖÐʹÓÃ%s ˵Ã÷·ûÀ´ÊµÏÖ×Ö·û´®ÊäÈëʱ£¬
Óöµ½¿Õ¸ñ¡¢ »»Ðзû»áÍ£Ö¹»ñÈ¡£¬ ËùÒÔËü¸üÆ«ÏòÓÚ»ñÈ¡µ¥´Ê¡£
4¡¢puts()º¯Êý
º¯Êý¹¦ÄÜ£ºÊä³ö×Ö·û´® int puts(const char *s);
º¯ÊýÔÐÍ£ºputs(Êý×éÃû)£»»òÕßputs(×Ö·û´®³£Á¿)
Ìص㣺ÔÚÊä³öÊý¾ÝµÄʱºò£¬¿ÉÒÔ×Ô¶¯»»ÐÐ
putsº¯ÊýÔÚÊä³öÊý¾ÝµÄʱºò£¬¿ÉÒÔʶ±ðתÒå×Ö·û
¾ÖÏÞ£ºÒ»´ÎÖ»ÄÜÊä³öÒ»¸ö×Ö·û´®£¬±íʾÓöµ½'\0'¾Í»á½áÊø
×¢Ò⣺Óë printf()²»Í¬,puts()ÏÔʾ×Ö·û´®Ê±×Ô¶¯ÔÚÆäºóÌí¼ÓÒ»¸ö»»Ðзû(enter¼ü)¡£
×¢Ò⣺fgets ¿ÉÒÔÖ¸¶¨Ä¿±ê»º³åÇøµÄ´óС£¬ËùÒÔÏà¶ÔÓÚ gets °²È«£¬µ«ÊÇ fgets µ÷ÓÃʱ£¬Èç¹ûÎļþÖе±Ç°ÐеÄ×Ö·û¸öÊýÓÚ size£¬ÔòÏÂÒ»´Î fgets µ÷ÓÃʱ£¬½«¼ÌÐø¶ÁÈ¡¸ÃÐÐʣϵÄ×Ö·û,fgets ¶ÁÈ¡Ò»ÐÐ×Ö·ûʱ£¬±£ÁôÐÐβµÄ»»Ðзû¡£fputs ²»»áÔÚÐÐβ×Ô¶¯Ìí¼Ó»»Ðзû£¬µ«ÊÇ puts »áÔÚ±ê×¼Êä³öÁ÷ÖÐ×Ô¶¯Ìí¼ÓÒ»»»Ðзû¡£Èç¹ûÔÚÎļþÖнøÐл»ÐеÄʱºò£¬ÔòÐèÒª¼Ó»»Ðзû¡±\r\n¡±; fprintf(fp,"\r\n");ʾÀý£º
#include<stdio.h>
int main()
{
char buf[50] = {0};
FILE *fp =fopen("a.txt", "r+");
fgets(buf, 5, fp);
printf("buf =%s\n", buf);
fputs("1234567",fp);
fclose(fp);
return 0;
}