C 記錄C語言中由於粗心遇到的奇葩錯誤

2022-02-11 08:13:25 字數 456 閱讀 7572

1.

正確**:

for( word = strtok( buf, whitespace); word != null; word =strtok( null, whitespace)) {

if (strcmp(word,"

the" ) == 0 )

錯誤**:

for( word = strtok( buf, whitespace); word != null; word =strtok( null, whitespace));{

if (strcmp(word,"

the" ) == 0 )

錯誤原因: 由於多了個分號.所以for迴圈體中實際執行的**是 ; 這行空語句, if語句則變成了迴圈體外,

所以在呼叫strcmp中,引數word將永遠為null.

C語言中獲取時間記錄

最近在網路上找了乙個cpu和gpu矩陣乘法對比的demo 在linux中執行,一直報錯 error identifier gettickcount is undefined 這是因為gettickcount是windows中的函式,需要引入標頭檔案windows.h,當然,在linux中這種方法並不...

C語言中的聯合體 (記錄)

在c語言中,一種和結構體非常類似的語法,叫做共用體 union 它的定義格式為 union 共用體名 結構體和共用體的區別在於 結構體的各個成員會占用不同的記憶體,互相之間沒有影響 而共用體的所有成員占用同一段記憶體,修改乙個成員會影響其餘所有成員。結構體占用的記憶體大於等於所有成員占用的記憶體的總...

學習C語言中遇到的do while迴圈問題

學習c語言中遇到的問題 下面的程式中的do while迴圈在執行時只能輸入一次字元,第二次迴圈時會跳過,請問這是什麼原因?include include include include include int roll dice void bool play game void int main v...