找到 34423 篇文章,关于编程

在 C 语言中打印文件内容

Samual Sam
更新于 2020-06-26 07:56:43

6K+ 次浏览

这是一个在 C 语言中打印文件内容的示例。假设我们有一个名为“new.txt”的文件,其内容如下:0, hell!o 1, hello! 2, gfdtrhtrhrt 3, demo现在,让我们来看这个例子。示例#include <stdio.h> #include <conio.h> void main() { FILE *f; char s; clrscr(); f=fopen("new.txt", "r"); while((s=fgetc(f))!=EOF) { printf("%c", s); } fclose(f); getch(); }输出0, hell!o 1, hello! 2, gfdtrhtrhrt 3, demo在上面的程序中,我们有一个文本文件“new.txt”。文件指针用于打开和读取文件。它显示文件的内容。FILE *f; ... 阅读更多

在 C 语言中以写入模式打开现有文件 fopen()

karthikeya Boyini
更新于 2020-06-26 07:57:29

600 次浏览

函数 fopen() 打开指针指向的文件并读取或写入文件。在写入模式下,使用“w”,在读取模式下,使用“r”。当目录中存在文件时,它将其视为一个新的空文件,并用新数据覆盖文件内容。这是 C 语言中 fopen() 的语法:FILE *fopen(const char *filename, const char *access_mode)这里,filename − 要打开的文件名。acess_mode − 访问文件的模式,例如读取或写入模式。这是一个 C 语言中 fopen() 的示例,假设... 阅读更多

在 C 中使用 realloc()

Samual Sam
更新于 2020-06-26 07:58:12

12K+ 次浏览

realloc 函数用于调整之前由 malloc 或 calloc 分配的内存块的大小。这是 C 语言中 realloc 的语法:void *realloc(void *pointer, size_t size)这里,pointer − 指向之前由 malloc 或 calloc 分配的内存块的指针。size − 内存块的新大小。这是一个 C 语言中 realloc() 的示例,示例 在线演示#include <stdio.h> #include <stdlib.h> int main() { int n = 4, i, *p, s = 0; p = (int*) calloc(n, sizeof(int)); if(p == NULL) { printf("Error! memory not allocated."); ... 阅读更多

C语言中的EOF、getc()和feof()

karthikeya Boyini
更新于 2023-09-14 20:45:57

26K+ 次浏览

EOFEOF 代表文件结束。getc() 函数成功时返回 EOF。这是一个 C 语言中 EOF 的示例,假设我们有一个名为 "new.txt" 的文件,其内容如下。This is demo! This is demo!现在,让我们来看这个例子。示例#include <stdio.h> int main() { FILE *f = fopen("new.txt", "r"); int c = getc(f); while (c != EOF) { putchar(c); c = getc(f); } fclose(f); getchar(); return 0; }输出This is demo! This is demo!在上面的程序中,文件是用 fopen() 打开的。当整型变量 c ... 阅读更多

C语言中的fseek()与rewind()

Samual Sam
更新于 2020-06-26 08:00:08

2K+ 次浏览

fseek()C 语言中的 fseek() 用于将文件指针移动到特定位置。偏移量和流是函数参数中给出的指针的目标。如果成功,它返回零,否则返回非零值。这是 C 语言中 fseek() 的语法:int fseek(FILE *stream, long int offset, int whence)以下是 fseek() 中使用的参数:stream − 这是用于标识流的指针。offset − 这是距位置的字节数。whence − 这是添加偏移量的位置。whence 由以下常量之一指定。SEEK_END − 结尾... 阅读更多

C语言中的calloc()与malloc()

karthikeya Boyini
更新于 2020-06-26 08:01:39

2K+ 次浏览

calloc()calloc() 函数代表连续位置。它的作用类似于 malloc(),但它分配多个大小相同的内存块。这是 C 语言中 calloc() 的语法:void *calloc(size_t number, size_t size);这里,number − 要分配的数组元素个数。size − 以字节为单位分配的内存大小。这是一个 C 语言中 calloc() 的示例,示例 在线演示#include <stdio.h> #include <stdlib.h> int main() { int n = 4, i, *p, s = 0; p = (int*) calloc(n, sizeof(int)); if(p == NULL) { printf("Error! memory not allocated."); ... 阅读更多

C语言中的fgetc()和fputc()

Samual Sam
更新于 2020-06-26 08:02:42

4K+ 次浏览

fgetc()fgetc() 函数用于从文件中读取字符。如果成功,它返回文件指针指向的字符,否则返回 EOF。这是 C 语言中 fgetc() 的语法:int fgetc(FILE *stream)这是一个 C 语言中 fgetc() 的示例,假设我们有一个名为“new.txt”的文件,其内容如下:0, hell!o 1, hello! 2, gfdtrhtrhrt 3, demo现在,让我们来看这个例子:示例#include <stdio.h> #include <conio.h> void main() { FILE *f; char s; clrscr(); f=fopen("new.txt", "r"); while((s=fgetc(f))!=EOF) { printf("%c", s); } fclose(f); getch(); }这是... 阅读更多

C语言中的strcspn()

karthikeya Boyini
更新于 2020-06-26 07:52:51

249 次浏览

strcspn() 函数计算两个字符串中第一个匹配字符之前的字符数。它在“string.h”头文件中声明。它返回第一个字符串中第一个匹配字符出现之前的字符数。这是 C 语言中 strcspn() 的语法:size_t strcspn(const char *string1, const char *string2)这里,string1 − 要扫描的第一个字符串。string2 − 用于在第一个字符串中搜索匹配字符的第二个字符串。这是一个 C 语言中 strcspn() 的示例,示例 在线演示#include <stdio.h> #include <string.h> int main() { char str1[] = "Helloworld!"; char ... 阅读更多

C++ 中的 delete() 运算符

karthikeya Boyini
更新于 2020-06-26 07:54:39

383 次浏览

delete 运算符用于释放内存。用户可以使用此 delete 运算符来释放已创建的指针变量。这是 C++ 语言中 delete 运算符的语法:delete pointer_variable;这是释放已分配内存块的语法:delete[ ] pointer_variable;这是一个 C++ 语言中 delete 运算符的示例,示例 在线演示#include <iostream> using namespace std; int main () { int *ptr1 = NULL; ptr1 = new int; float *ptr2 = new float(299.121); int *ptr3 = new int[28]; *ptr1 = 28; cout<<

C++ 中的 isprint()

Samual Sam
更新于 2020-06-26 07:42:01

62 次浏览

isprint() 函数是预定义函数,它检查传递的字符是否可打印。如果成功,它返回非零值,否则返回零。此函数在“cctype”头文件中声明。这是 C++ 语言中 isprint() 的语法:int isprint(int character);这里,character − 要检查的字符。这是一个 C++ 语言中 isprint() 的示例,示例 在线演示#include <iostream> #include <cctype> using namespace std; int main() { int val1 = 28; int val2 = 's'; int val3 = ''; if(isprint(val1)) cout<<

广告
© . All rights reserved.