当前位置: 首页 > news >正文

南京小程序开发费用珠海seo推广

南京小程序开发费用,珠海seo推广,浙江省住建厅网站,网站建设与制作的毕业论文文章目录 1. fopen函数2. fclose函数3. fgetc函数4. fgets函数5. fputc函数6. fputs函数7. fprintf函数8. fscanf函数9. fseek函数10. ftell函数 1. fopen函数 返回值:文件指针(FILE*)参数:文件名(包括文件路径&#…

文章目录

    • 1. fopen函数
    • 2. fclose函数
    • 3. fgetc函数
    • 4. fgets函数
    • 5. fputc函数
    • 6. fputs函数
    • 7. fprintf函数
    • 8. fscanf函数
    • 9. fseek函数
    • 10. ftell函数

1. fopen函数

  • 返回值:文件指针(FILE*)
  • 参数:文件名(包括文件路径)、打开模式(例如:"r"表示只读,"w"表示写入,"a"表示追加)
  • 用法:用于打开一个文件,并返回一个文件指针,以便后续的文件操作。
#include <stdio.h>int main() {FILE *file = fopen("example.txt", "r");if (file == NULL) {printf("Failed to open the file.\n");return 1;}// 文件操作...fclose(file);return 0;
}

2. fclose函数

  • 返回值:整数类型(0表示成功,EOF表示失败)
  • 参数:文件指针(FILE*)
  • 用法:用于关闭一个已打开的文件。
#include <stdio.h>int main() {FILE *file = fopen("example.txt", "r");if (file == NULL) {printf("Failed to open the file.\n");return 1;}// 文件操作...fclose(file);return 0;
}

3. fgetc函数

  • 返回值:整数类型(读取的字符的ASCII码值,读取失败返回EOF)
  • 参数:文件指针(FILE*)
  • 用法:用于从文件中读取一个字符。
#include <stdio.h>int main() {FILE *file = fopen("example.txt", "r");if (file == NULL) {printf("Failed to open the file.\n");return 1;}int ch;while ((ch = fgetc(file)) != EOF) {printf("%c", ch);}fclose(file);return 0;
}

4. fgets函数

  • 返回值:字符指针(读取的字符串,读取失败返回NULL)
  • 参数:字符数组、最大读取字符数、文件指针(FILE*)
  • 用法:用于从文件中读取一行字符串。
#include <stdio.h>int main() {FILE *file = fopen("example.txt", "r");if (file == NULL) {printf("Failed to open the file.\n");return 1;}char buffer[100];while (fgets(buffer, 100, file) != NULL) {printf("%s", buffer);}fclose(file);return 0;
}

5. fputc函数

  • 返回值:整数类型(写入的字符的ASCII码值,写入失败返回EOF)
  • 参数:字符、文件指针(FILE*)
  • 用法:用于向文件中写入一个字符。
#include <stdio.h>int main() {FILE *file = fopen("example.txt", "w");if (file == NULL) {printf("Failed to open the file.\n");return 1;}char ch = 'A';fputc(ch, file);fclose(file);return 0;
}

6. fputs函数

  • 返回值:整数类型(成功返回非负值,失败返回EOF)
  • 参数:字符串、文件指针(FILE*)
  • 用法:用于向文件中写入一个字符串。
#include <stdio.h>int main() {FILE *file = fopen("example.txt", "w");if (file == NULL) {printf("Failed to open the file.\n");return 1;}char *str = "Hello, World!";fputs(str, file);fclose(file);return 0;
}

7. fprintf函数

  • 返回值:整数类型(成功返回写入的字符数,失败返回负值)
  • 参数:文件指针(FILE*)、格式化字符串、可变参数
  • 用法:用于按照指定的格式将数据写入文件。
#include <stdio.h>int main() {FILE *file = fopen("example.txt", "w");if (file == NULL) {printf("Failed to open the file.\n");return 1;}int num = 10;fprintf(file, "The number is: %d\n", num);fclose(file);return 0;
}

8. fscanf函数

  • 返回值:整数类型(成功返回读取的项目数,失败返回负值)
  • 参数:文件指针(FILE*)、格式化字符串、可变参数
  • 用法:用于从文件中按照指定的格式读取数据。
#include <stdio.h>int main() {FILE *file = fopen("example.txt", "r");if (file == NULL) {printf("Failed to open the file.\n");return 1;}int num;fscanf(file, "%d", &num);printf("The number is: %d\n", num);fclose(file);return 0;
}

9. fseek函数

  • 返回值:整数类型(0表示成功,非0表示失败)
  • 参数:文件指针(FILE*)、偏移量(long int)、起始位置(int)
  • 用法:用于设置文件指针的位置,实现文件的定位操作。

10. ftell函数

  • 返回值:长整型(当前文件指针的位置)
  • 参数:文件指针(FILE*)
  • 用法:用于获取文件指针的当前位置。

下面是fseek和ftell函数的示例代码:

#include <stdio.h>int main() {FILE *file = fopen("example.txt", "r");if (file == NULL) {printf("Failed to open the file.\n");return 1;}// 使用fseek函数定位文件指针到文件末尾fseek(file, 0, SEEK_END);// 使用ftell函数获取文件指针的当前位置long int size = ftell(file);printf("The size of the file is: %ld bytes\n", size);fclose(file);return 0;
}

在上述示例代码中,首先打开了一个文件,然后使用fseek函数将文件指针定位到文件末尾,接着使用ftell函数获取文件指针的当前位置,即文件的大小。最后关闭文件。

使用fseek函数和ftell函数可以实现文件的定位和随机读写操作。



http://www.hkea.cn/news/794456/

相关文章:

  • 如何网站开发1688网站
  • 丽水专业网站建设价格青岛网站优化
  • 网站开发专业培训学校百度推广登录官网入口
  • 贵阳做网站公司网站热度查询
  • 做课件最好的素材网站考拉seo
  • 网站建设玖首选金手指seo网站优化收藏
  • 台州卓远做网站好不好广州seo教程
  • dz网站数据备份bt磁力猪
  • github 可以做网站吗360seo
  • 杭州 企业门户网站建设爱链
  • dj那个网站做的好长沙公司网络营销推广
  • 设计师培训招生视频黑帽seo联系方式
  • 做网上贸易哪个网站好西宁网站seo
  • 电子烟网站建设杯子软文营销300字
  • 广州企业网站制作怎么做营销推广
  • 网站建设服务器在香港郑州网站建设专业乐云seo
  • 河北建设工程交易信息网海口关键词优化报价
  • 全国网站建设公司有多少家微信朋友圈广告投放收费标准
  • 免费做网站公司黑帽seo排名技术
  • apk连接wordpress上海seo
  • 企业建网站租用服务器好还是买一个好石家庄网站关键词推广
  • wordpress文件解析外贸网站优化
  • 建设工程竣工备案网站百度保障中心人工电话
  • 韶关城乡建设部网站首页营销型网站建设策划书
  • 建设银行手机银行下载官方网站谷歌浏览器网页版入口在哪里
  • 网站建设 好域名注册信息
  • 公众号微网站建设认证哪个推广网站好
  • 爬取1024上传到wordpress蔡甸seo排名公司
  • 流感吃什么药更好seo的方法
  • 营销型网站建设市场seo黑帽技术有哪些