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 ...
随机推荐
- C# 结构转化
一.string 转 char[] string ss = "alsofly"; char[] cc = ss.ToCharArray(); 二.char[] 转 string c ...
- Javascript备忘模式
使用备忘模式,利用了函数的自定义属性,先看一个例子 var test = function (){} test.myAttr = "attr"; 这样,就给test加上了一个自定义 ...
- javac编译、运行
java源码(包结构) 源码存放位置:C:/Users/liaolongjun/DeskTop/java/ package test; import test.sub.F; public class ...
- javaWeb中servlet开发(3)——Servlet生命周期
生命周期:是一个程序的存在周期,servlet由于是受容器的管理,所以容器来决定其生命周期 1.servlet生命周期 2.servlet生命周期对应的方法 3.servlet生命周期代码 publi ...
- 字节流与字符流的区别&&用字节流好还是用字符流好?
字节流: (A)FileOutputStream(File name) 创建一个文件输出流,向指定的 File 对象输出数据. (B)FileOutputStream(FileDescriptor) ...
- 带你玩转JavaWeb开发之三 - CSS从基础到实战
一,什么是CSS? Cascading Style Sheets层叠样式表 层叠:就是层层覆盖叠加,如果有多种样式对同一html标签进行修饰,样式有冲突的部分应用优先级高,不冲突的 ...
- Ubuntu 14.04 升级gcc 4.8到gcc 5.x
简介 有些软件比较新,需要更高的gcc版本,所以需要升级gcc.编译安装比较耗时,所以直接选择bin包就好. 步骤 添加源 sudo add-apt-repository ppa:ubuntu-too ...
- Pivot C# WPF 代码添加PivotItem
PivotItem new_PivotItem = new PivotItem();//新建Pivotitem ListView new_ListView = new ListView();//新建l ...
- windows的Timer和写文件方式串口注意!
1.Timer要读取并分发消息,才能触发自定义回调函数 SetTimer(NULL, 1, 40, (TIMERPROC)TimerProc); while(GetMessage(&msg, ...
- LeetCode Maximum Size Subarray Sum Equals k
原题链接在这里:https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/ 题目: Given an array nums an ...