這幾個函式包含了型別、運算子和表示式在內的許多知識點,例子中使用了具體主函式來檢驗其效果,各個函式都有其十分有用的功能:
strlen - 計算字串長度atoi - 將數字字串轉換為對應數值
lower - 將大寫字母轉換為小寫
squeeze - 將與要求相符的字元從字串中刪去
strcat - 將兩個字串連線起來
getbit - 得到對應二進位制位數的另乙個數
bitcount - 得到數值對應二進位制數中1的位數
/×strlen函式:返回s的長度×/
#include
int strlen(char s)
int main()
注意點:
/*atoi函式:用於將一串數字轉換為相應數值*/
#include
#define maxline 1000
int atoi(char s)
int main()
if(c == '\n')
line[i] = c;
printf("%d\n",atoi(line));
return
0;}
注意點:
#include
/*lower函式:將字元由大寫轉換為小寫(如果字元為大寫形式的話)*/
int lower(int c)
int main()
if(c == '\n')
s[i] = c;
for(i=0;s[i] != '\n';i++)
s[i] = lower(s[i]);
printf("%s\n",s);
return
0;}
注意點:
#include
#include
int main()
注意點:
#include
//squeeze函式:從字串s中刪除字元c
void squeeze(char s,int c)
int main()
//正確輸出:2332234567
注意點:
if(s[i] != c)
s[j++] = s[i];
if(s[i] != c)
#include
//strcat函式:將字串t連線到字串s的尾部;前提是s有足夠大空間
void strcat(char s,char t)
int main()
//正確輸出結果:let's compile a c program
注意點:
#include
//squeeze函式:從字串s中刪除與字串c中任一字元相符的字元
void squeeze(char s,char t)
s[l] = '\0';
}int main()
//正確輸出:3334567
注意點:
#include
//getbits函式:返回x中從第p位開始的n位
unsigned getbits(unsigned x,int p,int n)
int main()
注意點:
#include
//bitcount函式:統計x中值為1的二進位制位數
int bitcount(unsigned x)
int main()
注意點:
#include
/*lower函式:將字元由大寫轉換為小寫(如果字元為大寫形式的話)*/
int lower(int c)
int main()
if(c == '\n')
s[i] = c;
for(i=0;s[i] != '\n';i++)
s[i] = lower(s[i]);
printf("%s\n",s);
return
0;}
注意點:
《c程式語言》
我的C程式語言學習日記 03
書中第三章講的是控制流,包括條件語句 if else巢狀語句 switch分支結構和三個迴圈結構 while do while語句 for迴圈 另外還有break continue語句 goto語句與標號,這裡只記了其中一些簡單的知識點。include binsearch函式 在v 0 v 1 v ...
我的C程式語言學習日記 04
對以下3個簡單的程式進行編譯連線 main.c程式 include int main max.c程式 int max int a,int b min.c程式 int min int a,int b return a1 主程式main.c中使用include語句包含連線程式源 檔案 main.c程式中...
c語言學習日記(九)
上三角矩陣指主對角線以下的元素都為0的矩陣 主對角線為從矩陣的左上角至右下角的連線。本題要求編寫程式,判斷乙個給定的方陣是否上三角矩陣。輸入格式 輸入第一行給出乙個正整數t,為待測矩陣的個數。接下來給出t個矩陣的資訊 每個矩陣資訊的第一行給出乙個不超過10的正整數n。隨後n行,每行給出n個整數,其間...