目前分類:標準函式庫 (4)

瀏覽方式: 標題列表 簡短摘要

出現下列錯誤訊息時,只要在gcc compiler加上後面的 -lm 即可解決。

Rwh_FilterModule.c:(.text+0x1412): undefined reference to `sqrt'
Rwh_FilterModule.c:(.text+0x1430): undefined reference to `cos'

文章標籤

S 發表在 痞客邦 留言(0) 人氣()

使用fgets()常會遇到一個問題,輸入的字元數目超過Buffer給定的,就會出現下列的狀況。

狀況:當程式為 fgets( cName, 30, stdin ); 時,輸入超過30 個字元,程式就會每次輸出30個字元直到全部資料被輸出。下列為此種現象程式碼及狀況示意圖 :

#include <stdio.h>
#include <string.h>
int main()
{
    char cName[30];
    FILE *pFile;

    pFile = fopen( "write.csv", "a" );
    if( pFile == NULL )
    {
        printf("open failure");
        return 1;
    }
    while(1)
    {
        printf("please enter your name: \n");
        fgets( cName, 30, stdin );
        if( 'E' == cName[0] && ('\n' == cName[1] || '\0' == cName[1] ))
        {
            break;
        }

        fwrite(cName, 1, strlen( cName ) , pFile);
        memset( cName, 0x00, sizeof( cName ) );

    }
    fclose(pFile);
    return 0;
}
                                                                                           

 

文章標籤

S 發表在 痞客邦 留言(0) 人氣()

gets() 取得使用者輸入的全部字串,包括空白字元。

char * gets ( char * str );

scanf() 取得使用者輸入的字串,遇到空白字元就停止取得。

文章標籤

S 發表在 痞客邦 留言(0) 人氣()

printf()之使用功能為將指定的文字、數字等等...顯示在螢幕上,使用此函數必須先#include <stdio.h>

小試身手小範例(1)

#include <stdio.h>

文章標籤

S 發表在 痞客邦 留言(0) 人氣()