• 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. 洛谷 P1125 笨小猴

    P1125 笨小猴 题目描述 笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼.但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大! 这种方法的具体描述如下:假设max ...

  2. typedef 与 set_new_handler的几种写法

    可以用Command模式.函数对象来代替函数指针,获得以下的好处: 1. 可以封装数据 2. 可以通过虚拟成员获得函数的多态性 3. 可以处理类层次结果,将Command与Prototype模式相结合 ...

  3. Android开发之Volley网络通信框架

    今天用了一下Volley网络通信框架,感觉挺好用的,写个博客记录一下用法.方便以后VC. Volley(Google提供的网络通信库,能使网络通信更快,更简单,更健壮.) 功能模块: 1. JSON, ...

  4. 之前搭建的jenkins的一些笔记

    wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo rpm --import http:// ...

  5. quartz-misfire 错失、补偿执行

    调度(scheduleJob)或恢复调度(resumeTrigger,resumeJob)后不同的misfire对应的处理规则 misfire产生的条件是:到了该触发执行时上一个执行还未完成,且线程池 ...

  6. java实习生的成长之路<转>

    首先初识语法的阶段,必须要学会怎么操作对象,操作if和for,操作list set map,然后是线程.IO和jdbc什么的,其余的,若是一时不理解,可以后边需要时再学. 这阶段完了,你可以写些能在控 ...

  7. 机器学习(三) Jupyter Notebook, numpy和matplotlib的详细使用 (上)

    工欲善其事,必先利其器.在本章,我们将学习和机器学习相关的基础工具的使用:Jupyter Notebook, numpy和matplotlib.大多数教程在讲解机器学习的时候,大量使用这些工具,却不对 ...

  8. org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner$1

    不能加载或找不到 org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner$1 经查证,是mybatis-spring-xxx.jar 这个版 ...

  9. 分享js中 pageY = clientY + document.body.scrollTop 之间的关系

    //这里没有考虑兼容ie模式下 兼容一般主流浏览器 var $1 = document.getElementById('main') $1.onclick = function(e){ console ...

  10. ASP.NET通过JavaScript实现Button 的Enabled=false

    正常代码控制无法满足需求,所以记录一下方法: <input id="Button5" onclick=" CX()" type="button& ...