我的问题是能够计算c中字符串中单引号或双引号的数量。例子
String Single Quote Count Double Quote Count
'hello world' 2 0
'hell'o world' 3 0
"hello world" 0 2
"hello" world" 0 3
用户输入字符串,我通过gets()函数获取,然后我需要这个计数器来进一步分析字符串。
例如,当我必须在我的字符串中计算 '|' 时,这会更容易
String | Count
hello | world 1
hello | wo|rld 2
所以我的功能很简单:
int getNumPipe(char* cmd){
int num = 0;
int i;
for(i=0;i<strlen(cmd);i++){
if(cmd[i]=='|'){ //if(condition)
num++;
}
}
return num;
}
但是现在我必须分析引号,我不知道该为 if(condition) 写什么
if(cmd[i]==''')??