• fprintf

     //从读文件中提取字符串到info1.user和info1.password中
    fscanf(pfr, "%s%s", info1.user, info1.password);
  • fscanf
     //格式化写入到文件中
    fprintf(pfw, "%d %s %s\n", i, info1.user, info1.password);
  • printf 和 scanf是特例
     //从字符串中取出,键盘缓冲区
    fscanf(stdin, "a=%s", str);
    //int string映射到一 个字符串 显示器缓冲区
    fprintf(stdout, "%s", str);

完整代码:

 #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h> //创建结构体
typedef struct info7k7k
{
char user[];
char password[]; }INOF,* PINOF; void main2x()
{
//以读的方式打开文件
FILE *pfr = fopen("7k7kOK.txt", "r");
//以写的方式打开文件
FILE *pfw = fopen("7k7kOKwithid.txt", "w");
//编号
int i = ;
//如果没到文件末尾
while (!feof(pfr))
{
i++;
//创建结构体
INOF info1;
//从读文件中提取字符串到info1.user和info1.password中
fscanf(pfr, "%s%s", info1.user, info1.password);
//格式化写入到文件中
fprintf(pfw, "%d %s %s\n", i, info1.user, info1.password);
}
//关闭文件
fclose(pfr);
fclose(pfw);
system("pause");
} void main3x()
{
//int num = fprintf(stdout, "helloword%s","1234");
//printf("\n%d", num);//fprintf返回值就是写入成功字符的个数
FILE *pf = fopen("C:\\x.txt", "r");
int num = fprintf(pf, "helloword%s", "");//写入失败返回-1
printf("\n%d", num);
system("pause");
} void main()
{
//char str[128] = { 0 };
//int numa;
//int numb;
//int num = fscanf(stdin, "%s%d%d",str,&numa,&numb);
////返回值是扫描到几个数据,失败返回-1
//printf("\n%d", num);
FILE *pf = fopen("C:\\x.txt", "w");
char str[] = { };
int numa;
int numb;
int num = fscanf(pf, "%s%d%d",str,&numa,&numb);
printf("\n%d", num); system("pause"); }

69.fprintf fscanf的更多相关文章

  1. fprintf, fscanf,printf,scanf使用时参数注意

    在利用fprintf函数将数据按格式输出到文件中时,通常需要限定数据的格式,例如: FILE *f=fopen("d:\\1.txt","w+"); int a ...

  2. 进程操作篇atexit execl exit fprintf fscanf getpid nice get priority printf setpid system vfork wait waitpid

    atexit(设置程序正常结束前调用的函数) 相关函数 _exit,exit,on_exit 表头文件 #include<stdlib.h> 定义函数 int atexit (void ( ...

  3. 函数fgets和fputs、fread和fwrite、fscanf和fprintf用法小结 (转)

    函数fgets和fputs.fread和fwrite.fscanf和fprintf用法小结 字符串读写函数fgets和fputs 一.读字符串函数fgets函数的功能是从指定的文件中读一个字符串到字符 ...

  4. C++之函数fgetc和fputc、fgets和fputs、fread和fwrite、fscanf和fprintf用法小结

    #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; int ...

  5. fscanf和fprintf

    fscanf和fprintf fscanf的字符串是在键盘的缓冲区,fprintf是在显示器的缓冲区. 1.函数原型: int fprintf(FILE *fp, const char *format ...

  6. MATLAB中提高fwrite和fprintf函数的I/O性能

    提高fwrite和fprintf函数的I/O性能 http://www.matlabsky.com/thread-34861-1-1.html     今天我们将讨论下著名的fwrite(fprint ...

  7. C文件读写

    0. 文件操作相关函数 1.  文件分为字符方式读写,字节方式(二进制方式)读写 fprintf / fscanf FILE * file; //全局定义 void save(Book books[] ...

  8. c语言之I/O函数

    c语言中常用的I/O函数 最常用的字符串的标准I/O函数有getchar().putchar().gets().puts().scanf().printf().fputs().fgets().getc ...

  9. I/O 函数总结

    经过一段时间的学习,发现字符处理时或者文件处理时,经常需要进行输入(读入)和输出,而可供选择的函数很多,现在反而容易搞混淆,下面就对常用的7个 输入输出函数 进行总结和比较,以便于区分和熟练掌握. 标 ...

随机推荐

  1. 洛谷 P1443 马的遍历

    P1443 马的遍历 题目描述 有一个n*m的棋盘(1<n,m<=400),在某个点上有一个马,要求你计算出马到达棋盘上任意一个点最少要走几步 输入输出格式 输入格式: 一行四个数据,棋盘 ...

  2. 洛谷 P2440 木材加工

    P2440 木材加工 题目背景 要保护环境 题目描述 题目描述: 木材厂有一些原木,现在想把这些木头切割成一些长度相同的小段木头(木头有可能有 剩余),需要得到的小段的数目是给定的.当然,我们希望得到 ...

  3. Ubuntu常见报错及解决方式汇总

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells Github:https://github.co ...

  4. Xcode加入应用图标以及启动界面

    寻找了许久的资料,记录下Xcode加入应用图标以及启动界面的学习笔记: 很实用的网址: 1.(苹果官网)Designing for iOS 2.iOS 8 人机交互指南 图标和图片的尺寸參考: 更加具 ...

  5. (WPF)XAML 过程式代码

    当代码编译.x:Code 元素的内容将被放到.g.cs文件. <Window x:Class="WpfApplication7.MainWindow" xmlns=" ...

  6. SQL Source Control

    https://documentation.red-gate.com/display/SOC5/SQL+Source+Control+5+documentation Working with migr ...

  7. leetcode 10 Regular Expression Matching(简单正则表达式匹配)

    最近代码写的少了,而leetcode一直想做一个python,c/c++解题报告的专题,c/c++一直是我非常喜欢的,c语言编程练习的重要性体现在linux内核编程以及一些大公司算法上机的要求,pyt ...

  8. canvas中遇到的理解问题

    1.lineDashOffset ctx.lineDashOffset = number 描述: setLineDash 用于设置开始绘制虚线的偏移量. 数字的正负表示左右偏移. 2.createLi ...

  9. Springboot分布式限流实践

    高并发访问时,缓存.限流.降级往往是系统的利剑,在互联网蓬勃发展的时期,经常会面临因用户暴涨导致的请求不可用的情况,甚至引发连锁反映导致整个系统崩溃.这个时候常见的解决方案之一就是限流了,当请求达到一 ...

  10. Android控件ToggleButton的使用方法

    ToggleButton(开关button)是Android系统中比較简单的一个组件,是一个具有选中和未选择状态双状态的button.而且须要为不同的状态设置不同的显示文本. ToggleButton ...