scanf()函数的一些小问题

longqzh posted @ 2010年6月19日 20:13 in Technic with tags scanf c , 2114 阅读

对于scanf()函数来说," ","\t","\n"并没有什么本质的区别,scanf()函数遇到这三种字符的时候会停止,但是这些字符会变成当前缓冲区中的字符。也就是 说,scanf("%d",&n);语句作用完之后,如果还有回车,那么scanf("%c",&ch);读入的就是一个回车。

但是scanf("\n")所读取的并不是一个回车,而是之后所有的" ","\t","\n"字符!其实这就是把缓冲区中所有的" ","\t","\n"字符都清空了。scanf(" ");和scanf("\t");在这方面的功能与scanf("\n");并没有什么区别。

相比之下,gets()要稍微规范一点,可惜的是gets()容易出现溢出错误,所以不建议使用。gets()仅仅是读入到"\n"字符为止,但是 与scanf()不同的是,gets()不会把这个遇到的"\n"字符放入缓冲区,而且gets()所跳过的仅仅是这一个"\n"字符!也就是 说,gets()函数永远是读入到当前行为止,并且自动转到下一行的开头。

Avatar_small
Primary Result Rajsh 说:
2022年8月27日 22:49

Here are the complete details about PSC Result 2022 Rajshahi Board or Division, and students you are at the correct location to check total PSC Exam GPA Grade marks 2022 with downloading of full mark sheet, Primary Result Rajshahi Division as per DPE announcement there are lacks of students participate in this year like previous years, and this year this number is reached up to 30 lacks from all divisions in the country. This year also the Primary School Certificate Examination has completed as per schedule for all divisions and those terminal exams are held without delay under Rajshahi education board functioning under DPE, now they are ready to announce PSC Result 2022 with Full Marksheet for all education boards in the country.

Avatar_small
SCERT Tripura 5th C 说:
2023年8月29日 19:40

Tripura 5th Class Model Question Paper 2024 are Prepared as per the updated Board of Education in the Tripura State Syllabus to help Students in their exam Preparations, which Aims to build both the Practical knowledge as well as analytical Skills for High School Every Student, SCERT Tripura Class Question Paper 2024 are Prepared as per the updated Tripura Board Class Syllabus to SCERT Tripura 5th Class Model Paper 2024 help Students in their Exam Preparations.Tripura Class Question Paper 2024 will help a lot to the Students to Estimate their writing speed in the Examination 2024, After Completing the Preparation of entire Syllabus.

Avatar_small
seo service london 说:
2023年11月01日 20:05

I adore each of the threads, I relished, I'd really like much more information with this, mainly because it is quite pleasant., Appreciate it intended for giving

Avatar_small
boardmodelpaper.com 说:
2024年1月18日 02:11

Board Model Papers 2024 Download with Suggestions for 10th Class Textbooks 2024 Pdf Download and SSLC New Syllabus Sample Question Paper 2024 and different types of model papers boardmodelpaper.com and question papers for following the website and Arts, Science, Commerce Stream Subject Wise Solved Question Bank for Hindi & English Medium Students with Exam Pattern & Blueprint and subject Wise with 11th & 12th Question Bank 2024 for General & Vocational Course Languages & Subjects Important Question for the above link.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter