• 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. cocos2d-js导弹跟踪算法(一边追着目标移动一边旋转角度)

    跟踪导弹 function(targetPosition){ // 让物体朝目标移动的方法 ; var targetPoint = targetPosition; var thisPoint = cc ...

  2. php如何截取出视频中的指定帧作为图片

    php如何截取出视频中的指定帧作为图片 一.总结 一句话总结:截取视频指定帧为图片,php ffmpeg扩展已经完美实现,并且php ffmpeg是开源的 二.php如何截取出视频中的指定帧作为图片 ...

  3. BZOJ 3940 AC自动机

    思路: 需要维护一个栈的AC自动机--. 要求出来 最后的栈顶是在自动机上的哪个节点. if(!ac.ch[st[tp-1]][a[i]-'a']) st[tp]=ac.ch[ac.f[st[tp-1 ...

  4. 《读书报告 – Elasticsearch入门 》----Part II 深入搜索(1)

    Part II 深入搜索 搜索不仅仅是全文本搜索:数据的很大部分是结构化的值例如日期.数字.这部分开始解释怎样以一种高效地方式结合结构化搜索和全文本搜索. 第十二章 结构化搜索 结构化搜索_ 是指查询 ...

  5. OPENCV(4) —— ImgProc

    2D图像滤波器基础类BaseFilter:dst(x,y) = F(src(x,y), src(x+1,y)... src(x+wdith-1,y), src(y+1,x)... src(x+widt ...

  6. SQL语句查询数据库所有表和所有字段的详细信息(包括表描述和字段描述)

    select (case then ddd.value else '' end ) as "表名(中文)" --如果表名相同就返回空 , (case then d.name els ...

  7. while my time-- , will the meaning++?

    // while my time--,will the meaning++? // However,what's the meaning of life ? while(tomorrow>0){ ...

  8. python垃圾回收算法

    标准python垃圾回收器由两部分组成,即引用计数回收器和分代垃圾回收器(即python包中的gc module).其中,引用计数模块不能被禁用,而GC模块可以被禁用. 引用计数算法 python中每 ...

  9. 洛谷 P3040 [USACO12JAN]贝尔分享Bale Share

    P3040 [USACO12JAN]贝尔分享Bale Share 题目描述 Farmer John has just received a new shipment of N (1 <= N & ...

  10. C# ArcGIS Engine 使当前选中的操作失效(清除当前鼠标事件)

    问题描述: 前提:我用的ENGINE9.3开发,拖了一个ToolbarControl控件,加了一些常用操作的工具(平移,放大,缩小)在上边. 问题:我做了一个增加点的按钮.当我平移完地图之后,点击增加 ...