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 fp...

大家好,今天来说说字符的输入/输出。

// 从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 ***in ( ) { 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 ***in(){ 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 ***in (){ 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 ***in (){ 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 ***in (){ 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 ***in(){ 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 ***in () { char c; for (c = 'A' ; c <= 'Z' ; c++) putchar (c); return 0;}#include <stdio.h>int ***in () { char string [] = "Hello world!"; puts (string);}

今天就到这里,虽然上面的内容看起来很简单。

但是如果想用的自如,还是需要经常接触。

本文来自是我太自作多情投稿,不代表舒华文档立场,如若转载,请注明出处:https://www.chinashuhua.cn/24/591265.html

打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
() 0
上一篇 06-14
下一篇 06-14

相关推荐

  • 韩顺平php从入门到精通 php从入门到精通教程

    数组基础含义:数组是一系列数据的***,这些数据按照设定的顺序排列成“链状”。注意:php中数组单元的顺序与下标无关!数组定义(赋值):$arr1 = array(3,11,5,18,2);//这是最常见的数组,下标是“默认下标”,是从0开始的整数;$ arr 2 = array(" a " = >3、“bb”= &g

    2023-07-29 01:18:01
    299 0
  • 象棋入门教程从零开始 初学者入门最全教程,一看就懂

    中国象棋作为我国的国粹,已有几千年的历史,深受人民的喜爱。无论在公园、街道、居民区等。,随处可见下棋的人,周围都是看棋的人。看他们互相争论一会儿,指点迷津,真的很有意思。相信很多人也对象棋感兴趣,但是新手应该怎么下棋呢?新手应该怎么下棋?首先,棋盘和棋子1

    2023-07-26 16:56:01
    541 0
  • 微单反相机哪款好(入门微单反相机哪款好)

    随着微单相机逐渐成为影像市场的主导,无论是购买第一台相机的新用户,还是单反相机的老用户,面对市场上种类繁多的微单相机,应该如何选择?今天在这篇文章中,我们就以佳能EOS R系列专用微单相机为例,谈谈新人和老用户如何选择微单相机。目前市场上销售的佳能EOS R系列专用

    2023-07-25 21:47:01
    871 0
  • seo如何入门(seo入门基础教程)

    SEO是什么?什么是SEO?大家口中的SEO(搜索引擎优化)翻译成中文就是“搜索引擎优化”。本质上,就是如何迎合搜索引擎的规则,让网站在搜索结果中排名更靠前,比如某PDA行业网站。当用户输入“PDA数据采集器”时,如果没有SEO,可能这个网站会出现在第2页或第3页之后。通过用户

    2023-07-25 06:42:01
    353 0

评论列表

联系我们

在线咨询: QQ交谈

邮件:admin@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信