89 fcanf和fprintf

scanf、printf、putchar、getc、putc、fgets、fputs、sscanf、sprintf
fscanf和fprintf

fgets  从屏幕上获取输入(stdin)或者从文件中获取输入
fputs 
输入到屏幕上(stdout)或者输出到文件中.

scanf   从屏幕上的输入格式化分离.
printf  
输出到屏幕上.

sscanf  从字符串中格式化分离.
sprintf  输出到字符串中.

fscanf 
从文件中格式化分离.
fprintf 
输出到文件中.

fscanf
%d%c%d可能导致的bug

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int count(int one, int tow, char symbol) {
switch (symbol) {
case ‘+‘:
return one + tow;
case ‘-‘:
return one - tow;
case ‘*‘:
return one * tow;
case ‘/‘:
if (!tow) {
return 0;
}
else { return one / tow; }
}
}

void main() {
FILE*read = fopen("1", "r");
if (!read) {
printf("文件为空");
system("pause");
return;
}

FILE*write = fopen("1", "w");

int kong = NULL;
int xiaomiao = NULL;
while (!feof(read)) {
int one; int tow; char symbol;
fscanf(read, "%d%c%d=\n", &one, &symbol, &tow);
int shaomiao = ftell(read);
if (shaomiao != kong) {

int result = count(one, tow, symbol);
fprintf(write, "%d%c%d=%d\n", one, symbol, tow, result);

}
}

fclose(read);
fclose(write);
system("pause");
}

#include<stdio.h>
#include<stdlib.h>
void main() {
FILE*read = fopen("1.txt", "r");
if (!read) {
printf("文件为空");
system("pause");
return;
}

int kong = NULL;
int xiaomiao = NULL;
while (!feof(read)) {
char name[20] = { NULL };
int age = NULL;
fscanf(read, "%[^,],%d\n",&name,&age );
int shaomiao = ftell(read);
if (shaomiao != kong) {

printf( "名字%s,年龄%d\n",name,age);

}
}

fclose(read);

system("pause");

}

原文地址:https://www.cnblogs.com/xiaodaxiaonao/p/9069973.html

时间: 2024-08-10 03:03:05

89 fcanf和fprintf的相关文章

Socket网络编程--FTP客户端(2)(Windows)

上一篇FTP客户端讲到如果制作一个简单的FTP客户端,功能实现了,但是后面我们发现了问题,就是FTP是使用明文进行操作的.对于普通情况来说就无所谓了.但有时候要安全的一点的话,就应该使用FTP的安全版本.有SFTP和FTPs,两者都是FTP的安全版本,但是两者的实现原理差别还是很大的,具体自己搜索了解. 0.环境安装 环境使用我的这一篇文章安装好libssh2库. http://www.cnblogs.com/wunaozai/p/4528394.html 使用一个带有SFTP功能的FTP服务器

千穗谷大家空心砖接着看见数据库恢复

pinterest.com/youzhenqu/%E6%BF%89%E6%BA%AA%E5%8E%BF%E5%93%AA%E9%87%8C%E6%9C%89%E6%89%BE%E5%B0%8F%E5%A7%90%E6%9C%8D%E5%8A%A1%E7%94%B5%E8%AF%9D%E4%BF%A1%E6%81%AF pinterest.com/youzhenqu/%E7%95%8C%E9%A6%96%E6%89%BE%E5%B0%8F%E5%A7%90%E4%B8%8A%E9%97%A8%E5

7. 及时发布。除非真正的用户接触到你的产品并给予反馈

7. 及时发布.除非真正的用户接触到你的产品并给予反馈,你永远都不会知道你的产品是好是坏. 8. 尽快发布,经常发布.不要惦记着再增加一些其它功能.只要能达到可以用来收集用户反馈的最小功能集合,那就发布它.收集反馈信息,反复这个过程,发布下一 个版本.下一个版本,越快越好.如果你3个月才发布出第一版面向用户的产品,你拖延的太久了.如果3个星期才发布一次更新包,你拖延的太久了.如果不能一 周几次,那每周发布一次更新.每3周发布一次重大更新. 9. 唯一有意义的事是你的产品的好坏.其它的都是鸡毛蒜皮

否极泰来接电话高科技电话施

http://www.yhd.com/ctg/s2/c19606-0-60977/%E8%BF%9E%E4%BA%91%E6%B8%AF%E6%B5%B7%E5%B7%9E%E5%8C%BA%E5%93%AA%E9%87%8C%E6%9C%89%E6%89%BE%E5%AD%A6%E7%94%9F%E5%A6%B9%E6%89%93%E7%82%AE%E4%B8%8A%E9%97%A8%E6%9C%8D%E5%8A%A1%E5%8C%85%E5%A4%9C%E7%94%B5%E8%AF%9D%2

fprintf与fwrite函数用法与差异

在C语言中有两个常见的保存文件的函数:fprintf 与 fwrite.其主要用法与差异归纳如下: 一.fprintf函数. 1.以文本的形式保存文件.函数原型为 int fprintf(FILE* stream,const char* format,[argument]),用法类似于printf函数,返回值是输出的字符数,发生错误时返回一个负值. 2.对应的读取函数为fscanf().函数原型为int fscanf(FILE* stream,const char* format,[argume

文件流:&quot;fopen&quot;,&quot;fclose&quot;,“ftell”&quot;fseek&quot;,&quot;fgets&quot;,&quot;fprintf&quot; ,“feof”,&quot;fwrite&quot;,&quot;fread&quot;

char const* filename="D:/hello.txt"; "fopen", FILE *fp=fopen(char const *name,char const mode); e.g:FILE *fp = fopen(filename,"wb"); 打开文件流,name为要打开文件的路径,如这里的filename:mode 为对文件的操作模式,通常使用:"wb"(写操作),"rb"(读操作)

微信公众平台开发(89) 高级群发接口

在这篇微信公众平台高级接口开发教程中,我们将介绍如何开发高级群发接口功能. 本文分为以下四个部分: 准备群发内容 选择群发对象 执行群发 接收群发结果 一.准备群发内容 群发内容可以是文本.图片.语音.视频.图文.群发文本只需要文本内容,其他内容需要获得相应的media_id. 1. 文本内容 文本内容就是一段文字,比如:"微信公众平台开发最佳实践" 2. 图片.语音.视频 要求如下: ? 图片(image): 128K,支持JPG格式 ? 语音(voice):256K,播放长度不超过

fscanf函数和fprintf函数、fgets函数和fputs函数、fread函数和fwrite函数

1. fscanf 函数和 fprintf 函数 1.1 fscanf 函数 fscanf 函数只能从文本文件中按格式输入.fscanf 函数和 scanf 函数相似,只是输入的对象是磁盘上文本文件的数据.函数的调用形式如下: fscanf( 文件指针,格式控制字符串,输入项表 ); 例如,若文件指针 fp 指向一个已打开的文本文件,a.b 分别为整型变量,则以下语句从 fp 所指的文件中读入两个整数放入变量 a 和 b 中: fscanf( fp, "%d%d", &a, &

LeetCode --- 89. Gray Code

题目链接:Gray Code The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must b