-1
如果我給變量s
和a
可變我不能能夠給輸入我得到運行時錯誤,我不能夠得到兩個char值A和B
#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;
}
'%c'需要一個地址。你傳給它一個字符。使用:'scanf(「%c」,&a);''。注意's'是可以的,因爲數組會衰減到指向其第一個成員的指針。 –
要讀取字符串,請使用:'scanf(「%s」,s) ;' –
請問您能告訴我們這個程序應該做什麼嗎? –