私の問題は、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(条件) に何を入れればよいかわかりません
if(cmd[i]==''')??