30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

printf("Number of items scanned = %d\n", items);<br />

printf("Favorite number = %d\n", number);<br />

printf("Favorite letter = %c\n", letter);<br />

printf("Favorite color = %s\n", color);<br />

printf("Desired salary = $%.2f\n", salary);<br />

}<br />

Output:<br />

Number of items scanned = 4<br />

Favorite number = 5<br />

Favorite letter = T<br />

Favorite color = green<br />

Desired salary = $3000000.00<br />

tmpfile<br />

Description: Creates a temporary file<br />

Include: <br />

Prototype: FILE *tmpfile(void)<br />

Return Value: Returns a stream pointer if successful; otherwise, returns a NULL<br />

pointer.<br />

Remarks: tmpfilecreates a file with a unique filename. The temporary file is<br />

opened in w+b(binary read/write) mode. It will automatically be<br />

removed when exitis called; otherwise the file will remain in the<br />

directory.<br />

Example: #include /* for tmpfile, printf, */<br />

/* FILE, NULL */<br />

int main(void)<br />

{<br />

FILE *mytempfile;<br />

if ((mytempfile = tmpfile()) == NULL)<br />

printf("Cannot create temporary file");<br />

else<br />

printf("Temporary file was created");<br />

}<br />

Output:<br />

Temporary file was created<br />

sscanf (Continued)<br />

Standard C Libraries with Math Functions<br />

2004 Microchip Technology Inc. DS51456B-page 265<br />

tmpnam<br />

Description: Creates a unique temporary filename<br />

Đối số: dòng con trỏ đến dòng mở<br />

định dạng kiểm soát chuỗi định dạng<br />

ap con trỏ đến một danh sách các đối số<br />

Quay trở lại giá trị: Trả về số ký tự được tạo ra hoặc một số âm nếu một<br />

lỗi xảy ra.<br />

Ghi chú: Đối số định dạng có cú pháp tương tự và sử dụng nó có trong<br />

printf.<br />

Để truy cập vào danh sách đối số chiều dài biến, apvariable phải<br />

khởi tạo bởi các va_startand vĩ mô có thể được khởi tạo lại bởi<br />

cuộc gọi bổ sung cho va_arg. Điều này phải được thực hiện trước khi vfprintf<br />

hàm được gọi. Gọi va_endafter trở về chức năng. Để biết thêm<br />

chi tiết xem stdarg.h.<br />

Ví dụ: # include / * Forvfprintf, fopen, * /<br />

/ * Fclose, printf, * /<br />

/ * FILE, NULL * /<br />

# include / * Cho va_start, * /<br />

/ * Va_list, va_end * /<br />

FILE * myfile;<br />

khoảng trống errmsg (const char * fmt, ...)<br />

{<br />

va_list ap;<br />

va_start (ap, fmt);<br />

vfprintf (myfile, fmt, ap);<br />

va_end (ap);<br />

}<br />

int main (void)<br />

{<br />

int num = 3;<br />

if ((myfile = fopen ("afile.txt", "w")) == NULL)<br />

printf ("Không thể mở afile.txt \ n");<br />

khác<br />

{<br />

errmsg ("Lỗi: Ký tự"% c 'không phải là% s \ n ",' a ',<br />

"Một số nguyên.");<br />

errmsg ("Lỗi: Yêu cầu% d% s% c", num,<br />

"Hoặc nhiều ký tự.", '\ N');<br />

}<br />

fclose (myfile);<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!