1.文件数据内容,元数据内容
i节点
ls -l err.txt
-rw-rw-r-- 1 csgec csgec 50 Jun 23 11:19 err.txt
-:普通文件(文件类型)
rw-:属主用户拥有可读可写的权限
1:表示硬链接数(链接有软链接和硬连接)
ln

csgec:用户名 组名
50:文件大小
Jun 23 11:19:创建时间
err.txt:文件名

2.内核(kenerl)空间(内核态)与用户空间(用户态)
3.文件描述符
在Linux中,用文件描述符代表一个打开的文件,其本质是一个非负的整数。
4.系统调用(system call)
因为用户空间的程序是不能直接访问内核,而很多功能必须由内核提供,因此,必须有一种方式能够进入内核空间。Linux系统定义了一系列函数用于进入内核空间完成功能。这一系列函数统称为系统调用。

系统调用可以被程序员直接调用,也可以被标C函数调用,还可以被系统命令调用。

程序运行起来之后称为进程

PCB
vim /usr/src/linux-headers-3.13.0-24/include/linux/sched.h
task_struct描述进程
files_struct *
cat /proc/sys/fs/file-max

标准IO:
1.文件操作的基本步骤
1.打开文件
所谓打开文件,就是建立用户程序与文件的联系,为文件开辟缓冲区
,使文件指针指向该文件,以便进行其它各种操作。
fopen();
2.操作文件
3.关闭文件
fclose();
关闭文件就是切断文件与程序的联系,将文件缓冲区中的内容写入磁盘,并释放文件缓冲区,禁止再对该文件进行操作。
2.打开文件
FILE *fopen("带路径的文件名","文件使用方式");
3.关闭文件
fclose(fp);

4.读
1.读一个字符
fgetc(fp)
getc(fp)
getchar(void)
2.读一行
fgets()
gets()
3.任意读(数据块读)
fread()
5.写
1.写一个字符
fputc(int,fp);
putc(int,fp);
putchar(int);
2.写一行
fputs(ptr,fp);
puts(pts);
3.任意写
fwrite();

6.格式化的读写
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
//str.sprintf();
int snprintf(char *str, size_t size, const char *format, ...);

int scanf(const char *format, ...);
int fscanf(FILE *stream, const char *format, ...);
int sscanf(const char *str, const char *format, ...);

7.刷新流
fflush(fp);

8.定位流
fseek(fp,offset,基准值)
SEEK_SET 文件开头
SEEK_CUR 当前位置
SEEK_END 文件末尾

fseek(fp,-10,SEEK_SET);//
fseek(fp,100,SEEK_END);//

ftell()

rewind()

9.文件流出错、结束

void clearerr(FILE *stream);

int feof(FILE *stream);

int ferror(FILE *stream);

int fileno(FILE *stream);

测行缓冲区的大小:

204*5 + 4 = 1024
stdin
stdout 行缓冲

stderr

用文件实现用户注册和登录,修改密码
struct user
{
char name[20];
int pwd;
};

/*************************************************************************
> File Name: fwrite.c
> Author: csgec
> Mail: longer.zhou@gmail.com
> Created Time: Mon 01 Aug 2016 02:41:50 PM CST
************************************************************************/

#include<stdio.h>
#include<string.h>
struct student
{
int num;
char name[24];
int age;

};

int main()
{
struct student s;
s.num = 1001;
strcpy(s.name,"zhangfei");
s.age = 20;

//1.open file
FILE *fp = fopen("a.txt","w");
if(fp == NULL)
{
perror("fopen");
return -1;
}
//2.
fwrite(&s,sizeof(s),1,fp);

//3.
fclose(fp);

}

/*************************************************************************
> File Name: test.c
> Author: csgec
> Mail: longer.zhou@gmail.com
> Created Time: Mon 01 Aug 2016 04:56:29 PM CST
************************************************************************/

#include<stdio.h>

int main()
{
int i;
for(i = 10000; i < 10300; i++)
{
fprintf(stdout,"%d",i);
}
pause();
}

AnsiIO的更多相关文章

随机推荐

  1. jQuery常用及基础知识总结(三)

    1.通过jquery的$()引用元素包括通过id.class.元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用dom定义的方法. 2. ...

  2. UIView的alpha、hidden、opaque 深入

    转载自:http://blog.csdn.net/wzzvictory/article/details/10076323 UIView的这几个属性让我困惑了好一阵子,通过翻看官方文档和stackove ...

  3. SDAU课程练习--problemG(1006)

    题目描述 Problem Description The highest building in our city has only one elevator. A request list is m ...

  4. libtiff库使用

    此文章为了记录我在使用libtiff库中的一些问题而写,将不断补充. libtiff库是读取和写入tiff文件最主要的一个开源库,但文档写的实在不敢恭维.相对资料也是异常稀少. libtiff库的安装 ...

  5. PHP 将MySQL数据导出csv

    1.查询数据 // 假设得到的数据格式如下 $result = array( array( "orderid" = "1110111", "shopi ...

  6. POP音原因

    一,通话时调节音量,有POP音. POP音产生原因在于,音量变化太大导致有POP音,需要以淡入淡出的方式调节音量.请申请MOLY00108114 & MOLY00108143这两个Modem ...

  7. PAT (Advanced Level) 1028. List Sorting (25)

    时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...

  8. git 与 github基本使用

    这里只对git 与 github的基本使用介绍,对于简单的步骤不做详细的说明,可以在网上搜索 一.git与github的安装与链接 1.git 安装:百度搜索"git",下载安装即 ...

  9. (中等) CF 585C Alice, Bob, Oranges and Apples,矩阵+辗转相除。

    Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples ...

  10. iOS navigationBar 的isTranslucent属性

    苹果文档: A Boolean value indicating whether the navigation bar is translucent (YES) or not (NO). The de ...