导航:首页 > 编程语言 > 编写简单的查找程序

编写简单的查找程序

发布时间: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();

阅读全文

与编写简单的查找程序相关的资料

热点内容
ps怎么将文件合并 浏览:747
java的日期格式化 浏览:981
电脑应用程序怎么关 浏览:986
微信上链接在哪个文件夹 浏览:691
欧姆龙安装打开找不到密钥文件 浏览:302
苹果基本表情 浏览:128
我的世界教育版编程在哪里 浏览:842
pong文件夹找不到 浏览:759
69版本黑切 浏览:997
杭州道富java 浏览:635
知道qq号查微博账号和密码 浏览:294
红手指自带哪些app 浏览:103
手机用公司网络会被监控哪些 浏览:409
什么叫py编程 浏览:370
微信红包尾数作弊器ios 浏览:280
ipad备份文件夹 浏览:555
vivo手机qq下载的文件在哪里 浏览:303
如何导出ug的编程档 浏览:343
编程课如何提到游戏 浏览:430
微信里怎么帮别人集赞 浏览:20

友情链接