本文目錄一覽:
- 1、c語言讀取數據
- 2、一道簡單的C語言題
- 3、c語言 字元串「exam\t\034」的長度為
- 4、下面程序的運行結果為什麼是EXAM啊? #include “stdio.h” main() { c
- 5、C語言中如何解釋ExamQuestions *eq=*iterCurrent
- 6、C語言函數問題
c語言讀取數據
很簡單 我先佔個座
寫完了 超出了我預計時間 6分鐘
data.in內容
1 mul 2
4 div 1
5 add 6
8 sub 6
4 mod 3
運行結果
1 * 2
4 / 1
5 + 6
8 – 6
4 % 3
Press any key to continue
代碼
#include stdio.h
#include stdlib.h
#include string.h
main()
{
int i,sel;
char line[100]={0},num1[5]={0},num2[5]={0},op[5]={0},oplist[5][5]={“mul”,”div”,”add”,”sub”,”mod”};
FILE *fp=fopen(“data.in”,”r”);;
if (fp==NULL)
{
printf(“Error 1\n”);
return 1;
exit(0);
}
while (fgets(line,sizeof(line)-1,fp))
{
sscanf(line,”%[0-9] %s %[0-9]\n”,num1,op,num2);
printf(“%s “,num1);
sel=-1;
for (i=0;i5;i++)
{
if (strcmp(oplist[i],op)==0)
{
sel = i;
break;
}
}
switch (sel)
{
case 0:printf(“* “);
break;
case 1:printf(“/ “);
break;
case 2:printf(“+ “);
break;
case 3:printf(“- “);
break;
case 4:printf(“%% “);
break;
default:
printf(“Error 2\n”);
return 2;
}
printf(“%s\n”,num2);
}
}
一道簡單的C語言題
答案為D
a[3]數組之中元素值(每一個數組元素都是結構體)
a[0] ={1, a[1]}
a[1] ={2,a[2]}
a[2] ={3,a[0]}
ptr =a[1];
選項A ptr-i++ = 1+1 =2;
選項B
ptr++-i =(ptr-i)++
此時ptr-i =2,由於是後綴,所以在此式子之後才變化
B、D就是++i,i++區別了。
選項C為
*ptr-i =*(ptr-i) //錯誤
選項D
++ptr-i = ++(ptr-i)
c語言 字元串「exam\t\034」的長度為
5.
“exam”是四個字元,’\t’是一個整體,是轉義字元,算一個字元,’\0’是結束符,標誌著字元串結束,後面的字元都不起作用了。
所以總共是4+1+1=6個字元。但字元串的長度一般不算末尾的’\0’,因此長度為5.
下面程序的運行結果為什麼是EXAM啊? #include “stdio.h” main() { c
指針p開始指向數組首地址,即字元e,執行循環表達式(*t!=『p』)為真,列印*t-32實際就是『e』-32=『E』 ,然後執行t++,使指針指向下一地址,即x字元……直至指向p字元時循環條件為假程序結束。
C語言中如何解釋ExamQuestions *eq=*iterCurrent
ExamQuestions *eq=*iterCurrent;
等效於下面兩個
ExamQuestions *eq;
eq=*iterCurrent;
因此, 如果 iterCurrent 也是定義為:
ExamQuestions *iterCurrent;
那麼上面的語句就是錯的.
C語言函數問題
1。argc 是你在命令行輸入字元串的個數 。(包括可執行文件名),所以在此例中 argc是2。
2。argv[1][i] 是你在命令行第二個字元串,即第一個參數字元串,此例中是「123」。
3。!=’\0′ : 『\0′ 是 字元串數組的結束標誌符, 作用是判斷字元數組是否結束。
4。鍵入的命令行是:執行exam.exe 參數是 「123」。
原創文章,作者:WTFT,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/139162.html