(1)输入一个字符串,并存入字符数组a中。(2)输入任何字符,在字符数组中查找该字符的位置。

(1)输入一个字符串,并存入字符数组a中。(2)输入任何字符,在字符数组中查找该字符的位置。编写程序。实现如下功能

#include<stdio.h>
void main() { char a[256],c,s[20]; int i,n;
  scanf("%s",a); scanf("%s",s); c=s[0];
  n=-1; i=0; while ( a[i]!=0 ) if ( a[i]==c ) { n=i; break; } else i++;
  printf("字符%c在字符串\"%s\"中",a);
  if ( n<0 ) printf("未找到。\n"); else printf("的第%d个字符位置。\n",n+1);
}

温馨提示:答案为网友推荐,仅供参考
相似回答