找到關於C語言的1356篇文章

C語言中的fseek() vs rewind()

Samual Sam
更新於 2020年6月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年6月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年6月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/C++中的isgreaterequal()

karthikeya Boyini
更新於 2020年6月26日 08:03:19

171 次瀏覽

isgreaterequal() 函式用於檢查第一個引數是否大於或等於第二個引數。它在C語言的“math.h”標頭檔案中宣告。成功時返回true,否則返回false。以下是C++語言中islessgreater()函式的語法:bool isgreaterequal(value1 , value2);其中,value1 − 將與value2進行檢查的第一個引數。value2 − 用於檢查value1是否大於或等於的第二個引數。以下是一個C++語言中isgreaterequal()函式的示例:示例 線上演示#include <iostream>#include <cmath>using namespace std;int main() { int val1 = ... 閱讀更多

C/C++中的strchr()函式

Samual Sam
更新於 2020年6月26日 08:03:47

313 次瀏覽

strchr()函式用於在字串中搜索字元。它搜尋作為第二個引數傳遞的字元的第一次出現,如果成功則返回指向該字元的指標,否則返回NULL。以下是C語言中strchr()函式的語法:char *strchr(const char *string , int character)其中,string − 要掃描以搜尋字元的字串。character − 要在字串中搜索的字元。以下是一個C語言中strchr()函式的示例:示例 線上演示#include <stdio.h>#include <string.h>int main() { char s[] = "Helloworld!"; char c = 'o'; ... 閱讀更多

C/C++中的strxfrm()

karthikeya Boyini
更新於 2020年6月26日 07:51:52

253 次瀏覽

strxfrm()函式將源字串轉換為當前區域設定,並將轉換後的字串的前幾個字元複製到目標位置。它在C語言的“locale.h”標頭檔案中宣告。以下是C語言中strxfrm()函式的語法:size_t strxfrm(char *destination, const char *source, size_t number)其中,destination − 將複製字元的目標指標。source − 要轉換的字串。number − 要複製的字元數。以下是一個C語言中strxfrm()函式的示例:示例#include <stdio.h>#include <locale.h>int main () { char s[10] = "HelloWorld"; char ... 閱讀更多

C/C++中的islessequal()

Samual Sam
更新於 2020年6月26日 07:52:25

178 次瀏覽

islessequalr()函式用於檢查第一個引數是否小於或等於第二個引數。它在“math.h”標頭檔案中宣告。如果成功,則返回true,否則返回false。以下是islessequal()函式的語法:bool islessequal(value1 , value2);其中,value1 − 將與value2進行檢查的第一個引數。value2 − 用於檢查value1是否小於或等於的第二個引數。以下是一個islessequal()函式的示例:示例 線上演示#include <iostream>#include <cmath>using namespace std;int main() { int val1 = 8; int val2 = 8; bool result; result = islessequal(val1, ... 閱讀更多

C語言中的strcspn()

karthikeya Boyini
更新於 2020年6月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/C++中的iswpunct()函式

Samual Sam
更新於 2020年6月26日 07:53:21

132 次瀏覽

iswpunct()函式用於檢查傳遞的寬字元是否為標點符號。如果它不是標點符號,則返回零,否則返回非零值。它在“cwctype”標頭檔案中宣告。以下是iswpunct()函式的語法:int iswpunct(wint_t character);以下是一個iswpunct()函式的示例:示例#include <iostream>#include <cwctype>using namespace std;int main() { wint_t a = '!'; wint_t b = 'a'; if(iswpunct(a)) printf("該字元是標點符號。"); else printf("該字元不是標點符號。"); if(iswpunct(b)) printf("該字元是標點符號。"); else printf("該字元不是… 閱讀更多

C/C++中的iswblank()函式

Samual Sam
更新於 2020年6月26日 07:55:24

151 次瀏覽

iswblank()函式用於檢查傳遞的寬字元是否為空白字元。它基本上是一個空格字元,它也考慮製表符(\t)。此函式在C語言的“ctype.h”標頭檔案中宣告,在C++語言的“cctype”標頭檔案中宣告。以下是C++語言中isblank()函式的語法:int iswblank(wint_t char);以下是一個C++語言中iswblank()函式的示例:示例 線上演示#include <iostream>#include <cwctype>using namespace std;int main() { wchar_t s[] = L"The space between words."; int i = 0; int count = 0; while(s[i]) { ... 閱讀更多

廣告
© . All rights reserved.