小编And*_*cut的帖子

如何标记C字符串的结尾?

这是函数的代码:

void pattern(char word[200], char asPattern[200]) {
    for (unsigned i = 0; i < strlen(word); i++) { // unsigned to remove warning
        if (strchr("aeiou", word[i]) != 0) asPattern[i] = '*';
        else asPattern[i] = '#';
}
Run Code Online (Sandbox Code Playgroud)

基本上这个函数用#的's'和元音替换单词中的辅音,并将新模式存储在asPattern字符串中.但是,如果我在屏幕上显示asPattern,它会显示正确的模式,后跟一堆未知符号(strlen(asPattern)等于211或for循环后的某个东西).我认为问题是asPattern的结尾没有标记,asPattern [strlen(asPattern)] ='/ 0'不起作用,我不知道还能做什么......

我不能使用std :: string,所以请耐心地使用C字符串.

c c++

0
推荐指数
1
解决办法
2389
查看次数

标签 统计

c ×1

c++ ×1