當前位置:編程學習大全網 - 編程軟體 - 編程中的字符匹配

編程中的字符匹配

#包含& amplt;stdio.h & ampgt;

intmain()

{

inti,index,count

chara,ch,str[80];

scanf("%c\n ",& ampa);

I = 0;

index =-1;

count = 0;

ch = getchar();

for(I = 0;ch!= ' \ ni++){

str & lt我& gt= ch

count++;

ch = getchar();

}

for(I = 0;我& amplt;數數;i++)

if(a = = str & lt;我& gt)

index = I;

如果(索引!=-1)

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

其他

printf(" not found ");

return0

}

擴展數據:

Getchar()用法:

getchar()函數用於從計算機終端(通常是鍵盤)輸入字符。getchar()函數只能接收壹個字符,其函數值是從輸入設備獲得的字符。

示例:

#包含& amplt;stdio.h & ampgt;

intmain(void)

{

intc

/* notethgetcharreadsfromsdinand

islinebuffered這意味著將

notreturnuntilyoupressENTER。*/

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

printf("%c ",c);

return0

}

註意:可以使用getchar()函數讓程序員在程序調試結束後返回編輯界面前按鍵盤。用法:主函數結束,返回0;在其前面添加getchar();

  • 上一篇:C++編程求加速度,哪裏錯了!程序如下:
  • 下一篇:arm體系結構有哪幾種工作狀態?
  • copyright 2024編程學習大全網