文章插圖

文章插圖
// 從stream中讀取字符int fgetc ( FILE * stream );int putc ( int character, FILE * stream );int getc ( FILE * stream );// 從stream中讀取字符串char * fgets ( char * str, int num, FILE * stream );// 向stream中寫入字符int fputc ( int character, FILE * stream );//int putc ( int character, FILE * stream );// 向stream中寫入字符串int fputs ( const char * str, FILE * stream );// 從標準輸入(stdio)讀取一個字符int getchar ( void );// 從標準輸入(stdio)讀取一個字符串char * gets ( char * str );// putcharWrite character to stdout (function )putsWrite string to stdout (function )ungetcUnget character from stream (function )下面我們來看看實例代碼 。#include <stdio.h>int main ( ){FILE * pFile;int c;int n = 0;pFile=fopen ("myfile.txt","r");if (pFile==NULL)perror ("Error opening file");else{do {c = fgetc (pFile);if (c == '$') n++;} while (c != EOF);fclose (pFile);}return 0;}#include <stdio.h>int main(){FILE * pFile;char mystring [100];pFile = fopen ("myfile.txt" , "r");if (pFile == NULL)perror ("Error opening file");else {if ( fgets (mystring , 100 , pFile) != NULL )puts (mystring);fclose (pFile);}return 0;}#include <stdio.h>int main (){FILE * pFile;char c;pFile = fopen ("alphabet.txt","w");if (pFile!=NULL) {for (c = 'A' ; c <= 'Z' ; c++)fputc ( c , pFile );fclose (pFile);}return 0;}#include <stdio.h>int main (){FILE * pFile;char sentence [256];printf ("Enter sentence to append: ");fgets (sentence,256,stdin);pFile = fopen ("mylog.txt","a");fputs (sentence,pFile);fclose (pFile);return 0;}#include <stdio.h>int main (){int c;puts ("Enter text. Include a dot ('.')"" in a sentence to exit:");do {c=getchar();putchar (c);} while (c != '.');return 0;}#include <stdio.h>int main(){char string [256];printf ("Insert your full address: ");// warning: unsafe (see fgets instead)gets (string);printf ("Your address is: %sn",string);return 0;}#include <stdio.h>int main (){char c;for (c = 'A' ; c <= 'Z' ; c++)putchar (c);return 0;}#include <stdio.h>int main (){char string [] = "Hello world!";puts (string);}【c語言或者符號怎么打1001無標題 C語言或符號怎么打】今天的內容就這么多了,以上的內容雖然看起來簡單 。但是,想要運用自如的話,還是需要大家勤加聯系的 。
- c語言讀取txt文件數據到鏈表 c語言讀取txt文件數據亂碼
- 學C語言軟件 學c語言的軟件
- c語言高級代碼編程圖 c語言高級代碼大全
- C語言賦值語句規則 c語言語法的賦值語句規則
- 構成c語言源程序的基本單位是語句 構成c語言源程序的基本單位是函數,所有函數名
- 怎么判斷素數C語言 素數判斷c語言程序代碼
- c語言申請內存空間指向數組 c語言申請內存空間 程序結束
- java語言要學多久 java語言學多久
- 簡要概述計算機語言的發展和分類 計算機語言發展階段分為
- ios系統開發語言 ios應用開發語言
