现代集团旗下公司介绍:怎么编该程序
来源:百度文库 编辑:杭州交通信息网 时间:2024/04/26 14:36:18
#include <iostream.h>
void main()
{char c[13]={'f','s','f','s','y','w','h','l','l','x','q','p','b'};
char pp;
int i,x=14;
cout<<"输入一个字符:";
cin>>pp;
for (i=0;i<=12;i++)
if (pp==c[i])
{x=i;break;}
if (x!=14)
cout<<"字符"<<pp<<"在数组下标为:"<<x<<endl;
else
cout<<"-1"<<endl;
}
#include "stdio.h"
main()
{
char a[80],s;
int i;
gets(a);
gets(s);
for(i=0;i<80;i++)
{
if(a[i])&&a[i]==s)
{
printf("%d\n",i);
break;
}
}
if(i==80)printf("-1\n");
}
#include <stdio.h>
#include <string.h>
int main()
{
char* s1 = "this is a test k";
char* s2 = "z";
//int strcspn(const char *s1, const char *s2)
int t = strcspn(s1,s2);
printf("%d\n",(t!=strlen(s1)?t:-1));
return 0;
}
这个问题不难, 不知道你有什么要求,c++ 标准库中的find就是作这个用的,
如果用c的话,库函数里就有,string.h中的
char *strchr(char *str,char ch)就用这个功能,
不过如果找不到返回的是空指针.
那你去学C语言