fseek函数c语言_使用示例的C语言中的fseek()函数

article/2025/8/6 13:09:19

fseek函数c语言

C中的fseek()函数 (fseek() function in C)

Prototype:

原型:

    int feek(FILE *stream, long int offset, int origin);

Parameters:

参数:

    FILE *stream, long int offset, int origin

Return type: int

返回类型: int

Use of function:

使用功能:

The fseek() function is used to set the file indicator pointer to the associate with the file stream according to the value of offset and starting point of the file. The prototype of the function fseek() is:

fseek()函数用于根据文件的偏移量和起点将文件指示符指针设置为与文件流相关联。 函数fseek()的原型为:

    int feek(FILE *stream, long int offset, int origin);

Here, the offset is number of bytes from the origin.

在这里, 偏移量是从原点起的字节数。

There are three macros in fseek() function:

fseek()函数中包含三个宏:

  1. SEEK_SET: Seek from start of file

    SEEK_SET:从文件开头查找

  2. SEEK_CUR: Seek from current location

    SEEK_CUR:从当前位置寻求

  3. SEEK_END: Seek from end of file

    SEEK_END:从文件末尾查找

C语言中的fseek()示例 (fseek() example in C)

#include <stdio.h>
#include <stdlib.h>
int main(){
//Initialize the file pointer
FILE *f;
//Take a array of characters 
char ch[100];
//Create the file for write operation
f=fopen("includehelp.txt","w");
printf("Enter five strings\n");	
for(int i=0;i<4;i++){
//take the strings from the users
scanf("%[^\n]",&ch);
//write back to the file
fputs(ch,f);
//every time take a new line for the new entry string 
//except for last entry.Otherwise print the last line twice
fputs("\n",f);
//clear the stdin stream buffer
fflush(stdin);
}
//take the strings from the users
scanf("%[^\n]",&ch);
fputs(ch,f);
//close the file after write operation is over
fclose(f);
//open a file
f=fopen("includehelp.txt","r");
printf("\n...............print the strings..............\n");
while(!feof(f)){
//takes the first 100 character in the character array 
fgets(ch,100,f);
//and print the strings
printf("%s",ch);
}
rewind(f);
printf("\n...............print the position before print a strings S..............\n");
fseek(f,0,SEEK_SET);
printf("the file indicator position is - %d\n",ftell(f));
printf("\n...............print the position after print a strings ..............\n");
fgets(ch,100,f);
printf("%s",ch);
fseek(f,0,SEEK_CUR);
//print the current location
printf("the file indicator position is - %d\n",ftell(f));    
printf("\n...............print the position after print all the strings ..............\n");
fseek(f,0,SEEK_END);
printf("the file indicator position is - %d\n",ftell(f)); 
//close the file
fclose(f);
return 0;
}

Output

输出量

fseek example in c

翻译自: https://www.includehelp.com/c-programs/fseek-function-in-c-language-with-example.aspx

fseek函数c语言


http://chatgpt.dhexx.cn/article/48RTNofL.shtml

相关文章

c语言feek函数读取中文出现乱码

c语言feek函数读取中文出现乱码 在文件操作的学习中,发现读取文件的中文时会出现乱码 当输入的文字改成英文时则不会出现乱码,于是猜想是否和中文与英文占用的字节有关系,实践得出结论,的确是字节搞的鬼,那么有趣了,如果恰好文件指针指向中文字节的一半时,这个指针指向…

vue element-ui自定义表头,动态添加表头,新增行、新增列、删除行、删除列

vue element-ui表格怎样自定义表头&#xff0c;动态添加表头&#xff0c;新增行、新增列、删除行、删除列 需求描述1.自定义表头&#xff0c;表头里插入输入框2.默认初始化几行几列占位3.新增行4.新增列5.右键点击行&#xff0c;进行删除行6.右键点击表头&#xff0c;进行删除列…

sql delete删除列_现有表操作中SQL DELETE列概述

sql delete删除列 In this article, we will explore the process of SQL Delete column from an existing table. We will also understand the impact of removing a column with defined constraints and objects on it. 在本文中,我们将探讨从现有表中删除SQL列的过程。 …

Notepad++快速删除列或者列位置增加相同内容

一、快速删除列(一列或者多列) 方法&#xff1a;鼠标选择范围的起始位置&#xff0c;按住AltShift&#xff0c;然后鼠标选择范围的结束位置 使用‘BackSpace’删除即可 二、快速增加列内容 方法&#xff1a;鼠标放在第一行某一列&#xff0c;按住AltShift&#xff0c;然后鼠…

poi移动列和删除列

Java poi 移动列 删除列 移动列删除列最后 移动列 从poi4.0.0开始&#xff0c;在sheet里面提供了一个移动列的api shiftColumns(int startColumn, int endColumn, final int n)&#xff0c; 移动开始列、结束列和移动列数。 需要注意的是&#xff0c; 移动到的列需要没有格式…

python删除csv某一列_python csv 删除列

广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 我的input.csv看起来是这样的: day,month,year,lat,long01,04,2001,45.00,120.0002,04,2003,44.00,118.00 我试图删除“year”栏及其所有条目。 总共有40多个条…

Sqlite删除列方法

sqlite中是不支持删除列操作的&#xff0c;所以网上alter table table_name drop column col_name这个语句在sqlite中是无效的&#xff0c;而替代的方法可以如下&#xff1a; 1.根据原表创建一张新表 2.删除原表 3.将新表重名为旧表的名称 示例例子如下 1.创建一张旧表Stu…

oracle中如何删除列,oracle如何删除列?

oracle删除列的方法&#xff1a;1、删除一列&#xff0c;代码为【ALTER TABLEtable_name DROP COLUMNcolumn_name;】&#xff1b;2、删除多列&#xff0c;代码为【ALTER TABLE table_name DROP(column1&#xff0c;】。 oracle删除列的方法&#xff1a; 1、删除一列 ALTER TABL…

pandas—删除某行或某列数据

首先&#xff0c;创建一个DataFrame格式数据作为举例数据。 # 创建一个DataFrame格式数据 data {a: [a0, a1, a2],b: [b0, b1, b2],c: [i for i in range(3)],d: 4} df pd.DataFrame(data) print(举例数据情况&#xff1a;\n, df)注&#xff1a;DataFrame是最常用的pandas对象…

【QT设计师】某视频视频源

#coding:utf8程序制作&#xff1a;冷鱼闲风 制作日期&#xff1a;2021年12月06日 申明&#xff1a;本程序仅供学习&#xff0c;请勿用作商业用途和违法行为。 ps&#xff1a;程序还有很多值得改进的地方&#xff0c;欢迎大神帮我指出可以优化的地方吧&#xff0c;谢谢大家。 #导…

html页面如何访问rtsp视频源

基本知识: 1. 目前web不能直接访问rtsp视频源(不考虑安装插件的情况) 2. html页面播放视频的四种方式 1.)视频文件(如mpeg,webm,部署最简单,实时性较差) 2.)webrtc协议, 实时性能最好 3.) websokect 协议, 需要自己封装,也有一些开源和商业库 4.)rtmp协议(需…

H5Stream配置视频源

H5Stream配置视频源 配置视频源主要有两种&#xff1a;配置设备、配置sdk&#xff1b;主要说明两种配置配置方式区别。 方式一&#xff1a;设备方式 此方式可能不支持云台控制&#xff0c;摄像头比较少情况可采用此配置。 方式二&#xff1a;设备SDK 可能很多同学不清楚此模…

Android电视盒子最强看电视app-tvbox配置(视频源)教程

今天给大家分享一下安卓tv上最强的看视频神器-tvbox的配置方法 tvbox是一款影视观看类的软件&#xff0c;各种影视资源都是为你免费提供的&#xff0c;还有海量热门影视为你提供电视直播&#xff0c;让你可以实时在线进行观看以及体验一样&#xff0c;超多影视剧内容你感兴趣的…

使用H5Stream实现rtsp视频流播放,在Vue项目中 (无插件、可多视频源播放、亲测可用)

本文主要介绍用H5Stream 在Web页面播放摄像头的RTSP视频流&#xff0c;从0到1的过程。包括WebSocket代理、h5ss.bat文件 运行一会就自己卡死了、H5ss服务死掉自动定时重启的脚本 等可以遇到的问题。 第一步&#xff1a; 点击这个链接下载 h5s-r12.13.0805.21-win64-release.z…

网络视频源地址抓包分析(3)之获取腾讯视频源码

有朋友问我如何获取网络腾讯的网络视频&#xff0c;今天翻了一下3年前写的代码&#xff0c;发现还能用&#xff0c;但没有太多注释&#xff0c;凑合看吧。获取的网络视频地址无任何广告&#xff0c;为CDN最后返回的结果&#xff0c;可直接播放或下载。有些视频过大&#xff0c;…

苹果海洋视频源直播源文件

苹果海洋视频源文件&#xff1a;【0708视频源.rar】 链接下载&#xff1a; https://wwr.lanzoui.com/i3OlOr4cc4j 二维码下载&#xff1a; 苹果海洋直播源文件&#xff1a;【0708直播源.rar】 链接下载&#xff1a; https://wwr.lanzoui.com/iHm9dr89vvg 二维码下载&…

推荐一款跨平台视频播放器:ZY-Player

欢迎关注我的公众号&#xff1a;「阿拉平平」 有需要的小伙伴可以在微信后台回复 zyplayer 获取安装包 之前和大家安利过一款在线视频播放器&#xff1a;h-player&#xff0c;通过导入视频源就可以聚合播放视频&#xff0c;省去搜索资源的时间。不过可惜的是&#xff0c;作者很…

2021-08-29json

异步加载&#xff1a; 如何实现&#xff1f;不会阻断HTML CSS的下载&#xff0c; defer&#xff1a;只有IE9以下能用 和htmlcss并行下载 也可以这样在里面写&#xff1a;代码可以写到内部 执行&#xff1a; 正常js标签:下载完毕执行&#xff0c;执行完后加载html&#xff0c;…

创建 RTSP RTMP 视频源(Windows/Linux)

1. 前言 由于项目需要实现 视频识别图像分类&#xff0c;网上能用的视频流又很少&#xff0c;所以需要自己搭建视频源进行本地测试。 本文记录在 Windows 以及 Linux 系统分别创建 RTSP、RTMP 视频源 进行测试。 2. 准备 2.1 视频 我们要准备好一份 mp4 格式的视频&#xff…