以回车符结束的字符串

来源:百度知道 编辑:UC知道 时间:2024/05/19 03:24:56
输入一个以回车符结束的字符串(少于80个字符),再输入一个字符,统计并输出该字符在字符串中出现的次数。然后再输出该字符串。
紧急紧急……
忘了说明是C语言程序做法……抱歉抱歉……

#include<stdio.h>
#include<string.h>
main()
{
char *p;
char a[80];
char b;
int i=0;
int j=0;
p=&a[0];
printf ("intput the string\n");
gets(a);
printf ("input the character\n");
scanf("%c",&b);

for (i=0;i<80;i++,p++)
{
if (*p==b)
{
j++;
}
}
printf ("%d\n",j);

printf ("%s",a);
}

C版的来啦

VB做法

'建立3个文本框 一个命令按钮

DIM Mystr as string 'Mystr是以回车符结束的字符串
DIM S as string '后来输入的一个字符
DIM I ,J as integer
Mystr=text1.text
s=text2.text
For I =1 TO LEN(Mystr)
if S=Mid(Mystr,I,1) then
j=j+1
endif
next

text3.text=j