如果我为变量 s
提供输入“hello”,为变量提供 a
我无法提供输入
#include<stdio.h>
#include<string.h>
int main(){
char s[100],a,b;
//i am not able to get this value,please help me how to get three variables s,a,b at runtime
scanf("%c",s);
scanf("%c",a);
scanf("%c",b);
int n=strlen(s),count=0;
for(int i=0;i<n;i++){
if(s[i]==a && s[i+1]== b)
count++;
}
printf("%d",count);
return 0;
}
最佳答案
首先尝试使用 scanf("%c",&a)
scanf 。
然后仅使用一个 scanf
读取三个变量。
试试这个程序,它将解决您的问题:
#include <stdio.h>
#include <string.h>
int main()
{
char s[100], a, b;
//i am not able to get this value,please help me how to get three variables s,a,b at runtime
scanf("%s %c %c", s, &a, &b);
int n = strlen(s), count = 0;
for(int i = 0; i < (n - 1); i++){
if(s[i] == a && s[i+1] == b)
count++;
}
printf("%d",count);
return 0;
}
关于c - 我收到运行时错误,我无法获取两个字符值 a 和 b,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44829972/