仅使用 C 在第一个条件下复制 string:while 循环中断
Copying string:while loop breaks on the first condtion only using C
我想复制一个字符串并想停止复制下一个字符是“\0”或“.”。
所以我写了
while((dest[i]=src[i])!='[=11=]'||src[i]=='.');
i++;
当字符为 '\0' 时,while 循环完美运行
但如果是 '.'
我必须为第二部分单独写一个 "if condition" 吗?为什么?
那里有一个无限循环。
while((dest[i]=src[i])!='[=10=]'||src[i]=='.'); // This is the end of the loop,
// with an empty statement.
此外,您需要稍微更改条件。
(dest[i]=src[i]) != '[=11=]' && src[i] != '.'
为了避免 while
和 if
语句之后的空语句问题,您可以更改编码标准,以便始终使用 {}
.
while ( (dest[i]=src[i]) != '[=12=]' && src[i] != '.' )
{
++i
}
我想复制一个字符串并想停止复制下一个字符是“\0”或“.”。 所以我写了
while((dest[i]=src[i])!='[=11=]'||src[i]=='.');
i++;
当字符为 '\0' 时,while 循环完美运行 但如果是 '.' 我必须为第二部分单独写一个 "if condition" 吗?为什么?
那里有一个无限循环。
while((dest[i]=src[i])!='[=10=]'||src[i]=='.'); // This is the end of the loop,
// with an empty statement.
此外,您需要稍微更改条件。
(dest[i]=src[i]) != '[=11=]' && src[i] != '.'
为了避免 while
和 if
语句之后的空语句问题,您可以更改编码标准,以便始终使用 {}
.
while ( (dest[i]=src[i]) != '[=12=]' && src[i] != '.' )
{
++i
}