C library function - rewind()
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()的更多相关文章
- C library function - freopen()
Description The C library function FILE *freopen(const char *filename, const char *mode, FILE *strea ...
- C library function - tmpfile()
Description The C library function FILE *tmpfile(void) creates a temporary file in binary update mod ...
- Macro definition of snprintf conflicts with Standard Library function declaration
Macro definition of snprintf conflicts with Standard Library function declaration 即将此处的宏定义注释掉,因为在VS2 ...
- [Swift]数学库函数math.h | math.h -- mathematical library function
常用数学函数 1. 三角函数 double sin (double);//正弦 double cos (double);//余弦 double tan (double);//正切 2 .反三角函数 d ...
- python bug the C library strftime function.
import timedef date2mktime(date, format_='%Y-%m-%d'): return int(time.mktime(time.strptime(date, for ...
- [工作积累] Android dynamic library & JNI_OnLoad
Bionic libc doesn't load dependencies for current .so file (diff from Windows or Linux) so a explici ...
- c++学习书籍推荐《Beyond the C++ Standard Library》下载
百度云及其他网盘下载地址:点我 作者简介 Björn Karlsson works as a Senior Software Engineer at ReadSoft, where he spends ...
- 【夯实PHP基础】PHP标准库 SPL
PHP SPL笔记 这几天,我在学习PHP语言中的SPL. 这个东西应该属于PHP中的高级内容,看上去很复杂,但是非常有用,所以我做了长篇笔记.不然记不住,以后要用的时候,还是要从头学起. 由于这是供 ...
- flex-mp3
Mp3Player.as package ddw.adobe { import flash.events.Event; import flash.events.IOErrorEvent; import ...
随机推荐
- alloc
注意,凡是用到指针的地方,一定要在堆中分配空间,否则指针释放了,那就不能够传值了. 将一个对象作为另外一个对象的成员变量,可以直接将两个对象联系起来.
- css 待处理
三角css http://www.jb51.net/article/42513.htm http://blog.aizhet.com/web/4382.html 实现图片灰度效果 http://www ...
- 盒模型--padding
突然增加padding会使盒子变大,所以要按实际情况做调整. 没有写padding的时候: <style>div{ background:gray;}</style></ ...
- awk实现按照某个字段排序
awk 'BEGIN{ FS="|"} { ary[$14,NR]=$0} END{ nrw=asorti(ary, newary) for(i=1;i<=nrw;i++) ...
- Nginx配置SSI
一.什么是SSISSI:Server Side Include,是一种基于服务端的网页制作技术,大多数(尤其是基于Unix平台)的web服务器如Netscape Enterprise Server等均 ...
- JS错误捕获
try/catch/finally错误捕获 try { //一旦try中出现错误,直接跳到执行catch的内容,执行完catch的内容,代码继续执行 throw new Error('错误'); // ...
- delphi关闭程序Close,application.Terminate与halt区别
当Close是一个主窗体时,程序会退出.Close会发生FormClose事件,FormCloseQuery事件Halt会发生FormDestory事件,Application.Terminate以上 ...
- Oracle事务之一:锁和隔离
Oracle事务之一:锁和隔离 一. 事务概述 事务管理是数据库处理的核心.数据库既要保证用户能并发地执行事务,还要保证数据库的一致性. 当第一条可执行的SQL开始执行,就隐形地开始了一个事务,直到遇 ...
- Leetcode: K-th Smallest in Lexicographical Order
Given integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n. N ...
- zjuoj 3605 Find the Marble
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3605 Find the Marble Time Limit: 2 Seco ...