25 scanf , printf, การรับข้อมูลจากผู้ใช้งาน


  • scanf อ่านค่าจากหน่วยนำเข้าข้อมูล เช่น คีย์บอร์ด
  • จะทำการเก็บค่าตาม format-string ที่ระบุไว้ เก็บไว้ตามที่อยู่ของตัวแปรที่กำหนดไว้
  • ตัวอย่าง
    scanf( “ %d , %f “ , &a , & b);
    เมื่อ a คือตัวแปรชนิด integer และ b คือชนิด float หรือ double
SequenceMeaning
\aBell (alert)
\bBackspace
\fForm feed
\nNew line
\rCarriage return
\tHorizontal tab
\vVertical tab
\\Backslash
\?Question mark
\’Single quotation
\”Double quotation
Specifierความหมายชนิดข้อมูล
%cSingle characterchar
%dSigned decimal integerint, short
%ldSigned long decimal integerlong
%fDecimal floating-point numberfloat, double
%sCharacter stringchar arrays
%uUnsigned decimal integerunsigned int, unsigned short
%luUnsigned long decimal integerunsigned long


No comments:

Post a Comment