導航:首頁 > 編程語言 > 編寫簡單的查找程序

編寫簡單的查找程序

發布時間:2025-01-28 07:01:48

A. 編寫程序實現在一個字元串中查找指定的字元(請用c語言作答)

#include<stdio.h>

int main()

{

int i,index,count;

char a,ch,str[80];

scanf("%c ",&a);

i=0;

index=-1;

count=0;

ch=getchar();

for(i=0;ch!=' ';i++){

str<i>=ch;

count++;

ch=getchar();

}

for(i=0;i&lt;count;i++)

if(a==str<i>)

index=i;

if(index!=-1)

printf("index=%d",index);

else

printf("Not Found");

return 0;

}

(1)編寫簡單的查找程序擴展閱讀:

getchar()用法:

getchar()函數的作用是從計算機終端(一般為鍵盤)輸入一個字元。getchar()函數只能接收一個字元,其函數值就是從輸入設備得到的字元。

例:

#include&lt;stdio.h&gt;

int main(void)

{

int c;

/*Note that getchar reads from stdin and

is line buffered;this means it will

not return until you press ENTER.*/

while((c=getchar())!=' ')

printf("%c",c);

return 0;

}

註:可以利用getchar()函數讓程序調試運行結束後等待編程者按下鍵盤才返回編輯界面,用法:在主函數結尾,return 0;之前加上getchar();

閱讀全文

與編寫簡單的查找程序相關的資料

熱點內容
在電腦上怎麼復制文件 瀏覽:496
我的世界文件夾mod在哪裡 瀏覽:525
蘋果5s測評 瀏覽:782
安全文件夾在哪裡下 瀏覽:643
catpart文件名怎麼設置 瀏覽:39
PDF檔文件怎麼另存為 瀏覽:402
網路機頂盒恢復出廠怎麼能下載 瀏覽:4
網頁元素代碼 瀏覽:67
讀書選擇版本的原因 瀏覽:992
如何用數據線傳文件 瀏覽:335
java使用jni 瀏覽:432
p970升級錯誤修復 瀏覽:119
米4文件管理在哪 瀏覽:376
ug編程用哪個版本最經典 瀏覽:420
javamysqljdbc導入 瀏覽:365
js某個js先執行 瀏覽:508
視頻文件怎麼變成兩個了 瀏覽:523
exle表格如何匹配數據 瀏覽:850
丑角怎麼畫app 瀏覽:57
潮州網站怎麼優化 瀏覽:16

友情鏈接