Does char array contain string?

↘锁芯ラ 提交于 2019-12-10 09:21:40

问题


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.


回答1:


  1. It will be much easier to use a single 1D array.

  2. strstr(buffer, s1) != null (once you've changed buffer into a 1D array)




回答2:


strstr



来源:https://stackoverflow.com/questions/4557557/does-char-array-contain-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!