[英]Seeing if a string contains a substring in C
I have the task of finding out if one of the many strings in my array contains an @
character. 我的任务是找出数组中的多个字符串之一是否包含@
字符。
Example - 范例-
I am @HOME or @SCHOOL
If the string does contain the @
i want to print out the string. 如果字符串中确实包含@
我想打印出字符串。
arr
is declared as follows arr
声明如下
char* arr[10][100];
I thought of using this 我想用这个
if(strstr(arr[j], "@") != NULL);
{
printf("hey\n");
}
but it prints out every single string whether or not they have the @. 但它会打印出每个字符串,无论它们是否带有@。
Remove semicolon after the if
condition. if
条件,请删除分号。 Like 喜欢
if(strstr(outputArr[j], "@") != NULL)
Because 因为
if(strstr(outputArr[j], "@") != NULL);
is equivalent to 相当于
if(strstr(outputArr[j], "@") != NULL)
{
}
C99-6.8.3 paragraph 3: C99-6.8.3第3段:
A null statement (consisting of just a semicolon) performs no operations. 空语句(仅由分号组成)不执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.