本帖最后由 bin554385863 于 2019-12-9 05:15 编辑 #include <stdio.h>
#include <string.h>
int func(const char *str)
{
int c = 1;
char cstr[strlen(str)+1];
strcpy(cstr, str);
for (char *i = cstr; *(i + 1) != '\0'; i++)
{
if (*i != ' ' && *(i+1) == ' ')
{
c++;
}
}
if(cstr[strlen(cstr) - 1] == ' ')
{
c = c - 1;
}
return c;
}
int main(int argc, char const *argv[])
{
char *cstr = "Let's go to room 209.";
printf("%d", func(cstr));
return 0;
}
====================================================
Microsoft Windows [版本 10.0.18363.476]
(c) 2019 Microsoft Corporation。保留所有权利。
E:\Users\admin\Documents\VScode\Code>c:\Users\admin\.vscode\extensions\ms-vscode.cpptools-0.26.2\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-hlrzprod.hg0 --stdout=Microsoft-MIEngine-Out-di1cm5cx.s1c --stderr=Microsoft-MIEngine-Error-s1vkov2d.qbw --pid=Microsoft-MIEngine-Pid-hmybkx1g.hrq --dbgExe=D:\MinGW\bin\gdb.exe --interpreter=mi
5
E:\Users\admin\Documents\VScode\Code> |