• 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. Raphaeljs入门到精通(一)

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...

  2. C#做的CPU内存使用率

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. Android4.42-Settings源代码分析之蓝牙模块Bluetooth(上)

    继上一篇Android系统源代码剖析(一)---Settings 接着来介绍一下设置中某个模块的源代码.本文依然是基于Android4.42源代码进行分析,分析一下蓝牙模块的实现.建议大致看一下关于S ...

  4. 51Nod 1405 树的距离之和(dp)

    1405 树的距离之和 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 给定一棵无根树,如果它有n个节点,节点编号从1到n, 求随意两点之间的距离( ...

  5. 两个对象值同样(x.equals(y) == true),但却可有不同的hash code,这句话对不正确?

    1.网上面试题 这是一道Java面试题.看了非常多答案都说不正确.能够看下面代码.就知道结果了 http://www.iteye.com/topic/485046第45题 答案是错误的 package ...

  6. 烦人的Facebook分享授权

    开发端授权app权限 facebook要求提交应用到他们平台, 并且还限制100mb, 坑爹死了, 果断使用google drive分享给他们, 最開始不确定分享给他们什么样的程序包, 结果审核没通过 ...

  7. commons-fileupload 多文件上传

    第三方的文件上传工具类,例如这个东东:http://www.oschina.net/p/commons-fileupload,解析的方法无非就是这样: 1:在 controller 中先 HttpSe ...

  8. DevExpress Report打印边距越界问题

    DevExpress  Report Print的时候,出现这样的问题:one or more margins are set outside the printable area of the pa ...

  9. How Blink works

    How Blink works Author: haraken@ Last update: 2018 Aug 14 Status: PUBLIC Working on Blink is not eas ...

  10. noip 2018 day2 T1 旅行 基环树 tarjan

    Code: #include<cstdio> #include<cstring> #include<string> #include<stack> #i ...