c语言或者符号怎么打(c语言入门代码大全)

来源:国外服务器 在您之前已被浏览:1 次
导读:目前正在解读《c语言或者符号怎么打(c语言入门代码大全)》的相关信息,《c语言或者符号怎么打(c语言入门代码大全)》是由用户自行发布的知识型内容!下面请观看由(国外主机 - www.2bp.net)用户发布《c语言或者符号怎么打(c语言入门代码大全)》的详细说明。
笨笨网美国主机,w ww.2 b p .n e t

c语言或者符号怎么打(c语言入门代码大全)

大家好,今天和大家聊一下字符的输入/输出。

// 从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);}

今天的内容就这么多了,以上的内容虽然看起来简单。

但是,想要运用自如的话,还是需要大家勤加联系的。

笨笨网美国主机,w ww.2 b p .n e t
提醒:《c语言或者符号怎么打(c语言入门代码大全)》最后刷新时间 2025-03-21 11:18:13,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《c语言或者符号怎么打(c语言入门代码大全)》该内容的真实性请自行鉴别。