search
HomeCommon ProblemWhat is the function of rewind

What is the function of rewind

Dec 18, 2020 pm 05:00 PM
c languagerewind()

函数rewind的作用是使文件位置指针重新返回文件的开始位置。函数rewind的功能是将文件指针重新指向一个流的开头,基本语法是“void rewind(FILE * stream)”。

What is the function of rewind

本教程操作环境:Windows10系统、Dell G3电脑。

函数rewind的作用是:使文件位置指针重新返回文件的开始位置。

C 库函数 - rewind()

功 能: 将文件内部的位置 指针重新指向一个流( 数据流/文件)的开头

注意:不是 文件指针而是文件内部的位置指针,随着对文件的读写文件的位置指针(指向当前读写字节)向后移动。而文件指针是指向整个文件,如果不重新赋值文件指针不会改变。

用 法: 

void rewind(FILE *stream);

头文件:  stdio.h

返回值:无

例如:从键盘输入一行字符,追加写入到一个文件中,再把该文件内容读出显示在屏幕上。

#include<stdio.h>
 
int main()
{
    FILE  *fp;
    char  ch;
    if((fp=fopen("C:\\Users\\dell\\Desktop\\abc.txt","ab+"))==NULL)
    {
        printf("\nCannot open file\nstrike any key exit\n");
        getchar();
        return 1;
    }
    printf("input a string:\n");
    ch=getchar();
    while(ch!='\n')
    {
        fputc(ch,fp);
        ch=getchar();
    }
    rewind(fp);        
    ch=fgetc(fp);          
    while(ch!=EOF)
    {
        putchar(ch);
        ch=fgetc(fp);
    }
    fclose(fp);
    return 0;
}</stdio.h>

程序第20行,rewind(fp);每输入一个字符,文件内部位置指针向后移动一个字节。写入完毕,该指针已指向文件末尾, 如果要把文件从头读出,须把指针移到文件头,利用rewind()函数。

运行结果:

更多编程相关知识,请访问:编程入门!!

The above is the detailed content of What is the function of rewind. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft