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

編寫簡單的查找程序

發布時間: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();

閱讀全文

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

熱點內容
maya粒子表達式教程 瀏覽:84
抖音小視頻如何掛app 瀏覽:283
cad怎麼設置替補文件 瀏覽:790
win10啟動文件是空的 瀏覽:397
jk網站有哪些 瀏覽:134
學編程和3d哪個更好 瀏覽:932
win10移動硬碟文件無法打開 瀏覽:385
文件名是亂碼還刪不掉 瀏覽:643
蘋果鍵盤怎麼打開任務管理器 瀏覽:437
手機桌面文件名字大全 瀏覽:334
tplink默認無線密碼是多少 瀏覽:33
ipaddgm文件 瀏覽:99
lua語言編程用哪個平台 瀏覽:272
政采雲如何導出pdf投標文件 瀏覽:529
php獲取postjson數據 瀏覽:551
javatimetask 瀏覽:16
編程的話要什麼證件 瀏覽:94
錢脈通微信多開 瀏覽:878
中學生學編程哪個培訓機構好 瀏覽:852
榮耀路由TV設置文件共享錯誤 瀏覽:525

友情鏈接