- scanf อ่านค่าจากหน่วยนำเข้าข้อมูล เช่น คีย์บอร์ด
- จะทำการเก็บค่าตาม format-string ที่ระบุไว้ เก็บไว้ตามที่อยู่ของตัวแปรที่กำหนดไว้
- ตัวอย่าง
scanf( “ %d , %f “ , &a , & b);
เมื่อ a คือตัวแปรชนิด integer และ b คือชนิด float หรือ double
Sequence | Meaning |
---|---|
\a | Bell (alert) |
\b | Backspace |
\f | Form feed |
\n | New line |
\r | Carriage return |
\t | Horizontal tab |
\v | Vertical tab |
\\ | Backslash |
\? | Question mark |
\’ | Single quotation |
\” | Double quotation |
Specifier | ความหมาย | ชนิดข้อมูล |
---|---|---|
%c | Single character | char |
%d | Signed decimal integer | int, short |
%ld | Signed long decimal integer | long |
%f | Decimal floating-point number | float, double |
%s | Character string | char arrays |
%u | Unsigned decimal integer | unsigned int, unsigned short |
%lu | Unsigned long decimal integer | unsigned long |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) // scanf | |
{ | |
setbuf(stdout,NULL); | |
int number; | |
float b[2]; | |
//printf("%d\n",&number); | |
printf("Enter\"number : "); | |
scanf("%d %f%f",&number,&b[0],&b[1]); | |
printf("%d , %f , %f",number,b[0],b[1]); | |
return 0; | |
} |