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

做电商在什么网站网络推广引流方式

做电商在什么网站,网络推广引流方式,包装设计网站banner,phpcms 做购物网站在 C 语言中,stdio.h 是一个非常重要的头文件,定义了一系列用于输入和输出的函数、变量和宏。本文将逐一介绍 stdio.h 中定义的函数,并提供每个函数的完整示例。 变量类型 在 stdio.h 中定义了三个变量类型: size_t&#xff1a…

在 C 语言中,stdio.h 是一个非常重要的头文件,定义了一系列用于输入和输出的函数、变量和宏。本文将逐一介绍 stdio.h 中定义的函数,并提供每个函数的完整示例。

变量类型

stdio.h 中定义了三个变量类型:

  1. size_t:无符号整数类型,通常用于表示内存大小。
  2. FILE:适合存储文件流信息的对象类型。
  3. fpos_t:适合存储文件中任何位置的对象类型。

宏定义

stdio.h 中定义了一些常用的宏:

  1. NULL:空指针常量的值。
  2. _IOFBF_IOLBF_IONBF:用于 setvbuf 函数的第三个参数。
  3. BUFSIZsetbuf 函数使用的缓冲区大小。
  4. EOF:表示文件结束的负整数。
  5. FOPEN_MAX:系统可以同时打开的文件数量。
  6. FILENAME_MAX:字符数组可以存储的文件名的最大长度。
  7. L_tmpnamtmpnam 函数创建的临时文件名的最大长度。
  8. SEEK_CURSEEK_ENDSEEK_SETfseek 函数中用于定位不同位置的宏。
  9. TMP_MAXtmpnam 函数可生成的独特文件名的最大数量。
  10. stderrstdinstdout:分别对应标准错误、标准输入和标准输出流。

函数介绍与示例

1. int fclose(FILE *stream)

关闭流 stream。刷新所有的缓冲区。

#include <stdio.h>int main() {FILE *fp;fp = fopen("test.txt", "w");fprintf(fp, "This is just a test.\n");fclose(fp);return 0;
}

2. void clearerr(FILE *stream)

清除给定流 stream 的文件结束和错误标识符。

#include <stdio.h>int main() {FILE *fp;int c;fp = fopen("test.txt", "r");clearerr(fp);while ((c = fgetc(fp)) != EOF) {putchar(c);}fclose(fp);return 0;
}

3. int feof(FILE *stream)

测试给定流 stream 的文件结束标识符。

#include <stdio.h>int main() {FILE *fp;fp = fopen("test.txt", "r");while (!feof(fp)) {putchar(fgetc(fp));}fclose(fp);return 0;
}

4. int ferror(FILE *stream)

测试给定流 stream 的错误标识符。

#include <stdio.h>int main() {FILE *fp;fp = fopen("test.txt", "r");if (ferror(fp)) {perror("Error reading file");} else {printf("File read successfully.\n");}fclose(fp);return 0;
}

5. int fflush(FILE *stream)

刷新流 stream 的输出缓冲区。

#include <stdio.h>int main() {FILE *fp;fp = fopen("test.txt", "w");fprintf(fp, "This is just a test.\n");fflush(fp); // Flush the buffer to ensure data is written immediatelyfclose(fp);return 0;
}

6. int fgetpos(FILE *stream, fpos_t *pos)

获取流 stream 的当前文件位置,并把它写入到 pos

#include <stdio.h>int main() {FILE *fp;fpos_t position;fp = fopen("test.txt", "r");fgetpos(fp, &position);printf("Current position in file: %lld\n", position);fclose(fp);return 0;
}

7. FILE *fopen(const char *filename, const char *mode)

使用给定的模式 mode 打开 filename 所指向的文件。

#include <stdio.h>int main() {FILE *fp;fp = fopen("test.txt", "w");if (fp == NULL) {perror("Error opening file");return -1;}fprintf(fp, "This is just a test.\n");fclose(fp);return 0;
}

8. size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)

从给定流 stream 读取数据到 ptr 所指向的数组中。

#include <stdio.h>int main() {FILE *fp;char buffer[20];fp = fopen("test.txt", "r");fread(buffer, sizeof(char), 10, fp);printf("Data read: %s\n", buffer);fclose(fp);return 0;
}

9. FILE *freopen(const char *filename, const char *mode, FILE *stream)

把一个新的文件名 filename 与给定的打开的流 stream 关联,同时关闭流中的旧文件。

#include <stdio.h>int main() {FILE *fp;fp = freopen("test.txt", "w", stdout);printf("This is redirected to test.txt\n");fclose(fp);return 0;
}

10. int fseek(FILE *stream, long int offset, int whence)

设置流 stream 的文件位置为给定的偏移 offset,参数 whence 意味着从给定的位置查找的字节数。

#include <stdio.h>int main() {FILE *fp;fp = fopen("test.txt", "r");fseek(fp, 5, SEEK_SET);printf("Character at position 5: %c\n", fgetc(fp));fclose(fp);return 0;
}

11. int fsetpos(FILE *stream, const fpos_t *pos)

设置给定流 stream 的文件位置为给定的位置。参数 pos 是由函数

fgetpos 给定的位置。

#include <stdio.h>int main() {FILE *fp;fpos_t position;fp = fopen("test.txt", "r");fgetpos(fp, &position);fseek(fp, 10, SEEK_SET);fsetpos(fp, &position);printf("Character at original position after seeking: %c\n", fgetc(fp));fclose(fp);return 0;
}

12. long int ftell(FILE *stream)

返回给定流 stream 的当前文件位置。

#include <stdio.h>int main() {FILE *fp;long int position;fp = fopen("test.txt", "r");fseek(fp, 0, SEEK_END);position = ftell(fp);printf("Size of file: %ld bytes\n", position);fclose(fp);return 0;
}

13. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)

ptr 所指向的数组中的数据写入到给定流 stream 中。

#include <stdio.h>int main() {FILE *fp;char buffer[20] = "Hello, World!";fp = fopen("test.txt", "w");fwrite(buffer, sizeof(char), 13, fp);fclose(fp);return 0;
}

14. int remove(const char *filename)

删除给定的文件名 filename,以便它不再被访问。

#include <stdio.h>int main() {if (remove("test.txt") == 0) {printf("File deleted successfully.\n");} else {perror("Error deleting file");}return 0;
}

15. int rename(const char *old_filename, const char *new_filename)

old_filename 所指向的文件名改为 new_filename

#include <stdio.h>int main() {if (rename("test.txt", "new_test.txt") == 0) {printf("File renamed successfully.\n");} else {perror("Error renaming file");}return 0;
}

16. void rewind(FILE *stream)

设置文件位置为给定流 stream 的文件的开头。

#include <stdio.h>int main() {FILE *fp;char c;fp = fopen("test.txt", "r");rewind(fp);c = fgetc(fp);printf("First character of file after rewinding: %c\n", c);fclose(fp);return 0;
}

17. void setbuf(FILE *stream, char *buffer)

定义流 stream 应如何缓冲。

#include <stdio.h>int main() {FILE *fp;char buffer[BUFSIZ];fp = fopen("test.txt", "w");setbuf(fp, buffer);fprintf(fp, "This is just a test.\n");fclose(fp);return 0;
}

18. int setvbuf(FILE *stream, char *buffer, int mode, size_t size)

另一个定义流 stream 应如何缓冲的函数。

#include <stdio.h>int main() {FILE *fp;char buffer[BUFSIZ];fp = fopen("test.txt", "w");setvbuf(fp, buffer, _IOFBF, BUFSIZ);fprintf(fp, "This is just a test.\n");fclose(fp);return 0;
}

19. FILE *tmpfile(void)

以二进制更新模式(wb+)创建临时文件。

#include <stdio.h>int main() {FILE *tmpfp;tmpfp = tmpfile();fprintf(tmpfp, "This is a temporary file.\n");fclose(tmpfp);return 0;
}

20. char *tmpnam(char *str)

生成并返回一个有效的临时文件名,该文件名之前是不存在的。

#include <stdio.h>int main() {char buffer[L_tmpnam];tmpnam(buffer);printf("Temporary file name: %s\n", buffer);return 0;
}

21. int fprintf(FILE *stream, const char *format, ...)

发送格式化输出到流 stream 中。

#include <stdio.h>int main() {FILE *fp;int num = 10;fp = fopen("test.txt", "w");fprintf(fp, "The number is: %d\n", num);fclose(fp);return 0;
}

22. int printf(const char *format, ...)

发送格式化输出到标准输出 stdout

#include <stdio.h>int main() {int num = 10;printf("The number is: %d\n", num);return 0;
}

23. int sprintf(char *str, const char *format, ...)

发送格式化输出到字符串。

#include <stdio.h>int main() {char buffer[20];int num = 10;sprintf(buffer, "The number is: %d\n", num);printf("%s", buffer);return 0;
}

24. int vfprintf(FILE *stream, const char *format, va_list arg)

使用参数列表发送格式化输出到流 stream 中。

#include <stdio.h>
#include <stdarg.h>int my_printf(FILE *stream, const char *format, ...) {va_list arg;int done;va_start(arg, format);done = vfprintf(stream, format, arg);va_end(arg);return done;
}int main() {FILE *fp;int num = 10;fp = fopen("test.txt", "w");my_printf(fp, "The number is: %d\n", num);fclose(fp);return 0;
}

25. int vprintf(const char *format, va_list arg)

使用参数列表发送格式化输出到标准输出 stdout 中。

#include <stdio.h>
#include <stdarg.h>int my_printf(const char *format, ...) {va_list arg;int done;va_start(arg, format);done = vprintf(format, arg);va_end(arg);return done;
}int main() {int num = 10;my_printf("The number is: %d\n", num);return 0;
}

26. int vsprintf(char *str, const char *format, va_list arg)

使用参数列表发送格式化输出到字符串。

#include <stdio.h>
#include <stdarg.h>int my_sprintf(char *str, const char *format, ...) {va_list arg;int done;va_start(arg, format);done = vsprintf(str, format, arg);va_end(arg);return done;
}int main() {char buffer[20];int num = 10;my_sprintf(buffer, "The number is: %d\n", num);printf("%s", buffer);return 0;
}

27. int fscanf(FILE *stream, const char *format, ...)

从流 stream 读取格式化输入。

#include <stdio.h>int main() {FILE *fp;int num;fp = fopen("test.txt", "r");fscanf(fp, "%d", &num);printf("The number read from file is: %d\n", num);fclose(fp);return 0;
}

28. int scanf(const char *format, ...)

从标准输入 stdin 读取格式化输入。

#include <stdio.h>int main() {int num;printf("Enter a number: ");scanf("%d", &num);printf("You entered: %d\n", num);return 0;
}

29. int sscanf(const char *str, const char *format, ...)

从字符串读取格式化输入。

#include <stdio.h>int main() {char str[] = "The number is: 10";int num;sscanf(str, "The number is: %d", &num);printf("Extracted number from string: %d\n", num);return 0;
}

30. int fgetc(FILE *stream)

从指定的流 stream 获取下一个字符(一个无符号字符),并把位置标识符往前移动。

#include <stdio.h>int main() {FILE *fp;int c;fp = fopen("test.txt", "r");while ((c = fgetc(fp)) != EOF) {putchar(c);}fclose(fp);return 0;
}

31. char *fgets(char *str, int n, FILE *stream)

从指定的流 stream 读取一行,并把它存储在 str 所指向的字符串内。当读取 (n-1) 个字符时,或者读取到换行符时,或者到达文件末尾时,它会停止,具体视情况而定。

#include <stdio.h>int main() {FILE *fp;char buffer[255];fp = fopen("test.txt", "r");while (fgets(buffer, 255, fp) != NULL) {printf("%s", buffer);}fclose(fp);return 0;
}

32. int fputc(int char, FILE *stream)

把参数 char 指定的字符(一个无符号字符)写入到指定的流 stream 中,并把位置标识符往前移动。

#include <stdio.h>int main() {FILE *fp;int c;fp = fopen("test.txt", "w");for (c = 'A'; c <= 'Z'; ++c) {fputc(c, fp);}fclose(fp);return 0;
}

33. int fputs(const char *str, FILE *stream)

把字符串写入到指定的流 stream 中,但不包括空字符。

#include <stdio.h>int main() {FILE *fp;fp = fopen("test.txt", "w");fputs("This is just a test.\n", fp);fclose(fp);return 0;
}

34. int getc(FILE *stream)

从指定的流 stream 获取下一个字符(一个无符号字符),并把位置标识符往前移动。

#include <stdio.h>int main() {FILE *fp;int c;fp = fopen("test.txt", "r");while ((c = getc(fp)) != EOF) {putchar(c);}fclose(fp);return 0;
}

35. int getchar(void)

从标准输入 stdin 获取一个字符(一个无符号字符)。

#include <stdio.h>int main() {int c;printf("Enter a character: ");c = getchar();printf("You entered: ");putchar(c);return 0;
}

36. char *gets(char *str)

从标准输入 stdin 读取一行,并把它存储在 str 所指向的字符串中。当读取到换行符时,或者到达文件末尾时,它会停止,具体视情况

而定。

#include <stdio.h>int main() {char str[255];printf("Enter a string: ");gets(str);printf("You entered: %s\n", str);return 0;
}

37. int putc(int char, FILE *stream)

把参数 char 指定的字符(一个无符号字符)写入到指定的流 stream 中,并把位置标识符往前移动。

#include <stdio.h>int main() {FILE *fp;int c;fp = fopen("test.txt", "w");putc('A', fp);fclose(fp);return 0;
}

38. int putchar(int char)

把参数 char 指定的字符(一个无符号字符)写入到标准输出 stdout 中。

#include <stdio.h>int main() {putchar('A');return 0;
}

39. int puts(const char *str)

把一个字符串写入到标准输出 stdout,直到空字符,但不包括空字符。换行符会被追加到输出中。

#include <stdio.h>int main() {puts("This is just a test.");return 0;
}

40. int ungetc(int char, FILE *stream)

把字符 char(一个无符号字符)推入到指定的流 stream 中,以便它是下一个被读取到的字符。

#include <stdio.h>int main() {FILE *fp;int c;fp = fopen("test.txt", "r");c = fgetc(fp);ungetc(c, fp); // Push the character back to the streamprintf("Character pushed back: %c\n", fgetc(fp)); // Now read it againfclose(fp);return 0;
}

41. void perror(const char *str)

把一个描述性错误消息输出到标准错误 stderr。首先输出字符串 str,后跟一个冒号,然后是一个空格。

#include <stdio.h>int main() {FILE *fp;fp = fopen("nonexistentfile.txt", "r");if (fp == NULL) {perror("Error opening file");return -1;}fclose(fp);return 0;
}

42. int snprintf(char *str, size_t size, const char *format, ...)

格式字符串到 str 中。

#include <stdio.h>int main() {char buffer[20];int num = 10;snprintf(buffer, 20, "The number is: %d\n", num);printf("%s", buffer);return 0;
}

以上是 stdio.h 中定义的所有函数的详细介绍和示例。该头文件是 C 语言中输入输出操作的核心,熟练掌握其中的函数将对编程工作大有裨益。

http://www.shuangfujiaoyu.com/news/23769.html

相关文章:

  • 互联网专线做网站怎么做数据关键词搜索爱站
  • wordpress 本地写文章惠东seo公司
  • 空壳网站清理哪里可以接广告
  • 网站的创新点有哪些网站快照优化公司
  • 做网站就要租服务器2024年阳性什么症状
  • 吉林省建设安全厅官方网站南京百度提升优化
  • 公司就我一个网站制作seo业务培训
  • 快速搭建网站的软件百度快速排名技术培训教程
  • 秀米编辑器优化方案的格式及范文
  • 如何建造网站网站营销与推广
  • 委托别人做网站侵权了今日头条(官方版本)
  • 企业站网站建设seo快速排名系统
  • 做推广便宜的网站有哪些网络销售是做什么的
  • 对做的网站的改进建议win7系统优化
  • 在网站怎么做代销长沙大型网站建设公司
  • 哪些网站做平面单页好看东莞百度推广排名优化
  • 用adsl做网站备案专业营销团队公司
  • 如何修改网站标题网站关键词优化推广哪家好
  • 网站服务器免费吗深圳seo推广培训
  • 哈尔滨手机网站制作魔贝课凡seo课程好吗
  • 茂名模板建站定制网站百度指数爬虫
  • .中国域名的网站seo效果检测步骤
  • 怎样简单做网站企业网站推广模式
  • 门户网站个人可以做100个免费推广b站
  • 电商网站开发岗位职责谷歌搜索引擎入口2023
  • 网站如何做301跳转网页设计个人主页
  • 做网站官网好处全球疫情最新数据
  • 做网站推广需要什么关键词优化报价查询
  • 网站功能框架好的竞价托管公司
  • 兰州网站建设网站建设软文新闻发布网站