1¡¢printf(¡°¸ñʽ¿ØÖÆ¡±£¬Êä³öÁбí)
2¡¢scanf(¡°¸ñʽ¿ØÖÆ¡±£¬È¡µØÖ·Áбí)
×¢Ò⣺printfº¯Êý,ºÍscanfº¯Êý¶¼Êǽ«Êý¾ÝÊä³öµ½Öնˣ¬»òÕß´ÓÖն˻ñÈ¡Êý¾Ý£¬ µ«ÊÇfprintfº¯Êý,ºÍfscanfº¯ÊýÔòÊǽ«Êý¾ÝÊä³ö´ÅÅÌÎļþ£¬»òÕß´Ó´ÅÅÌÎļþ »ñÈ¡Êý¾Ý¡£ËùÒÔËüÃǵĶÁд¶ÔÏó²»ÊÇÖն˶øÊÇ´ÅÅÌÎļþ
¶Áд £º´ÓÄÚ´æµÄ½Ç¶È¶øÑԵġ£
ÊäÈëÊä³ö£º´ÓÈ˵ĽǶȶøÑÔ¡£
¶Á£ºÒ²¾ÍÊÇÊäÈ룬±íʾÊý¾Ý´ÓÆäËüµÄµØ·½´«Êäµ½ÄÚ´æ
д£ºÒ²¾ÍÊÇÊä³ö£¬±íʾÊý¾Ý´ÓÄÚ´æ´«Êäµ½ÆäËüµÄµØ·½
3¡¢fprintf()º¯Êý
º¯Êý¹¦ÄÜ£ºÊä³öÄÚÈݵ½ÎļþÖÐ
º¯ÊýÔÐÍ£ºint fprintf(FILE*stream, const char *format, ...);
fprintf(ÎļþÖ¸Õë, ¸ñʽ×Ö·û´®, Êä³öÁбí);
º¯Êý˵Ã÷£º½«Êý¾Ý¾¹ý¸ñʽ»¯¿ØÖÆ·ûµÄ×÷Óã¬Êä³öÄÚÈݵ½ÎļþÖ¸ÕëËùÖ¸ÏòµÄ ÄÚ´æÖÐ
ʾÀý£º
intmain(){
inti=3;
floatt=4.5;
fprintf(fp,¡±%d,%6.2f¡±,i,t);
}
¸ÃÓï¾ä±íʾ½«ÕûÐͱäÁ¿iºÍʵÐͱäÁ¿tµÄÖ¸Õë°´ÕÕ%dºÍ%6.2fµÄ¸ñʽÊä³öµ½fpÖ¸ÏòµÄÎļþÉÏ
4¡¢fscanf()º¯Êý
º¯Êý¹¦ÄÜ£º´ÓÎļþÖжÁÈ¡ÄÚÈÝ
º¯ÊýÔÐÍ£ºintfscanf(FILE *stream, const char *format, ¡);
fscanf(fp, ¸ñʽ×Ö·û´®,ÊäÈë±íÁÐ);
º¯Êý˵Ã÷£º´ÓÎļþÖ¸ÕëfpËùÖ¸ÏòµÄÄÚ´æÖа´Ò»¶¨µÄ¸ñʽ×Ö·û´®¶ÁÈë
ʾÀý£º
int main(){
int i;
float t;
fscanf(fp,¡±%d,%6.2f¡±,&i,&t);
}
¸ÃÓï¾ä±íʾ¸Ãº¯Êý¿ÉÒÔ´Ó´ÅÅÌÎļþÉ϶ÁÈëASCII×Ö·û
Èç¹û´ÅÅÌÎļþÖÐÓÐÒÔÏÂ×Ö·û£º
3£¬4.5
Ôò´ÅÅÌÎļþÖеÄÊý¾Ý3Ë͸ø±äÁ¿i£¬4.5Ë͸ø±äÁ¿t£¬ÊäÈëµÄ¸ñʽҪÓë¸ñʽ×Ö·û´®µÄλÖÃÒ»Ò»¶ÔÓ¦