是否字符数组包含字符串? [英] Does char array contain string?
问题描述
我有一个文本文件,并想检查它是否包含一个字符串。
该文本文件存储在一个字符数组:字符缓冲区[512] [128];
Q1:这是比较容易,如果我在一个多头排列,而不是一个多维数组缓冲区呢?
Q2:我怎么能检查缓冲区是否包含字符串的char * S1 =世界,你好!;
?
我会需要搜索多个字符串。
-
这将是更容易使用一个单一的一维数组。
-
的strstr(缓冲,S1)
!= NULL (一旦你已经改变了缓存
成一维数组)
I have a text file and would like to check if it contains a string.
The text file is stored in a char array: char buffer[512][128];
.
Q1: Is it easier if I buffer it in one long array instead of a multidimensional array?
Q2: How could I check whether the buffer contains the string char *s1 = "Hello world!";
?
I will need to search for multiple strings.
It will be much easier to use a single 1D array.
strstr(buffer, s1)
!= null (once you've changedbuffer
into a 1D array)
这篇关于是否字符数组包含字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!