-
fputs
鎖定
- 中文名
- fputs
- 類 型
- 函數
- 作 用
- 向指定的文件寫入一個字符串
- 用 法
- int fputs(str,fp);
- 注 意
- str是字符型指針 fp是文件型指針
fputs函數作用
C語言庫函數,把字符串寫入到指定的流( stream) 中,但不包括空字符。
fputs函數原型
int fputs(const char *str, FILE *stream);
返回值:該函數返回一個非負值,如果發生錯誤則返回 EOF(-1)。
(1)str:這是一個數組,包含了要寫入的以空字符終止的字符序列。
(2)stream:指向 FILE 對象的指針,該 FILE 對象標識了要被寫入字符串的流
fputs示例
#include<stdio.h> #include<stdlib.h> int main() { char str[80]="asdhfdf\n"; FILE *fp = NULL; if((fp=fopen("strfile.txt","w"))==NULL) { printf("cannot open file\n"); exit(0); } fputs(str,fp); //putchar(str); fclose(fp); fp = NULL; return 0; }