我有 6 个 const 字符串(每个 5 个字母)
我得到了几个词(在这 6 个词中)。
我想计算每个单词出现了多少次。
如何在 C 中实现它?
我努力了:
char searchEngineNames[6][5] = { "waze_", "faceb", "fours", "googl",
"fueli", "yello" };
static void foo(const char* res_name, int success, void *context, char *last_modified) {
if (success){
for (int i=0; i<6; i++)
{
char substringFiveChars[6];
strncpy(substringFiveChars, res_name, 5);
char substringFiveChars[6];
substringFiveChars[5] = 0;
if (strcmp(searchEngineNames[i],substringFiveChars) == 0)
{
...
}
..
}
例如对于这个流:
"wooo_","wooo_","faceb","wooo_","google"
我最终会得到:
"wooo_" 3 times
"faceb" 1 times
"google" 1 times
"fours" 0 times
"fuelil" 0 times
"yello" 0 times