Description

The C library function void rewind(FILE *stream) sets the file position to the beginning of the file of the given stream.

Declaration

Following is the declaration for rewind() function.

void rewind(FILE *stream)

Parameters

  • stream − This is the pointer to a FILE object that identifies the stream.

Return Value

This function does not return any value.

Example

The following example shows the usage of rewind() function.

#include <stdio.h>

int main()
{
char str[] = "This is tutorialspoint.com";
FILE *fp;
int ch; /* First let's write some content in the file */
fp = fopen( "file.txt" , "w" );
fwrite(str , 1 , sizeof(str) , fp );
fclose(fp); fp = fopen( "file.txt" , "r" );
while(1)
{
ch = fgetc(fp);
if( feof(fp) )
{
break ;
}
printf("%c", ch);
}   //set the file position to the beginning, if it doesn't have this function, fp will point NULL ,because above while(1) and break when feof(fp) is true.
rewind(fp);
printf("\n");
while(1)
{
ch = fgetc(fp);
if( feof(fp) )
{
break ;
}
printf("%c", ch); }
fclose(fp); return(0);
}

Let us assume we have a text file file.txt that have the following content −

This is tutorialspoint.com

Now let us compile and run the above program to produce the following result −

This is tutorialspoint.com
This is tutorialspoint.com

C library function - rewind()的更多相关文章

  1. C library function - freopen()

    Description The C library function FILE *freopen(const char *filename, const char *mode, FILE *strea ...

  2. C library function - tmpfile()

    Description The C library function FILE *tmpfile(void) creates a temporary file in binary update mod ...

  3. Macro definition of snprintf conflicts with Standard Library function declaration

    Macro definition of snprintf conflicts with Standard Library function declaration 即将此处的宏定义注释掉,因为在VS2 ...

  4. [Swift]数学库函数math.h | math.h -- mathematical library function

    常用数学函数 1. 三角函数 double sin (double);//正弦 double cos (double);//余弦 double tan (double);//正切 2 .反三角函数 d ...

  5. python bug the C library strftime function.

    import timedef date2mktime(date, format_='%Y-%m-%d'): return int(time.mktime(time.strptime(date, for ...

  6. [工作积累] Android dynamic library & JNI_OnLoad

    Bionic libc doesn't load dependencies for current .so file (diff from Windows or Linux) so a explici ...

  7. c++学习书籍推荐《Beyond the C++ Standard Library》下载

    百度云及其他网盘下载地址:点我 作者简介 Björn Karlsson works as a Senior Software Engineer at ReadSoft, where he spends ...

  8. 【夯实PHP基础】PHP标准库 SPL

    PHP SPL笔记 这几天,我在学习PHP语言中的SPL. 这个东西应该属于PHP中的高级内容,看上去很复杂,但是非常有用,所以我做了长篇笔记.不然记不住,以后要用的时候,还是要从头学起. 由于这是供 ...

  9. flex-mp3

    Mp3Player.as package ddw.adobe { import flash.events.Event; import flash.events.IOErrorEvent; import ...

随机推荐

  1. NPOI简单操作excel

    本文仅当是个记录文件,仅供初学者参考. 首先得using几个npoi的空间名如下: using NPOI.HSSF.UserModel;using NPOI.HSSF.Util;using NPOI. ...

  2. Ubuntu每次启动都显示System program problem detected的解决办法

    Ubuntu每次启动都显示System program problem detected的解决办法 sudo gedit /etc/default/apport 将enabled=1改为enabled ...

  3. JSTL标签使用说明

    使用jstl需进行以下操作 a.下载jstl. b.解压jar文件将jstl.jar和standard.jar文件放到项目lib文件夹. c.在需要使用jstl地方引用标签库,比如在jsp页面引用以下 ...

  4. Android 网络通信框架Volley简介

    1.1. Volley引入的背景在以前,我们可能面临如下很多麻烦的问题. 比如以前从网上下载图片的步骤可能是这样的流程: 在ListAdapter#getView()里开始图像的读取. 通过Async ...

  5. openfire二次开发eclipse环境搭建

    转自:http://blog.csdn.net/daigua245/article/details/7918243 1.将openfire源码项目解压到(如果是从SVN CO下来的则不用)eclips ...

  6. find 找出大文件

    找到大文件 find . -type f -size +100M -exec du -smh {} \;

  7. js只允许输入数字

    <script type="text/javascript"> $(function () { $("[ID$=_PCT]").keyup(func ...

  8. sms-provider

    @ 最近测试 open-falcon. @ 首先得准备报警接口. sms-provider 邮件发送http接口: method: post params: content: 邮件内容 subject ...

  9. iOS10权限声明国际化

    iOS 10要求用户声明隐私访问用途,而且不能为空,否则将会被拒.被拒邮件如下: 解决办法是在Info.plist中添加Privacy - Camera Usage Description和Priva ...

  10. replace截取字段

    var a = '123:'b = '123:disfkajsdhfjkasdhf'c = b.replace(a, '')"disfkajsdhfjkasdhf"