是否字符数组包含字符串? [英] Does char array contain string?

查看:99
本文介绍了是否字符数组包含字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,并想检查它是否包含一个字符串。
该文本文件存储在一个字符数组:字符缓冲区[512] [128];

Q1:这是比较容易,如果我在一个多头排列,而不是一个多维数组缓冲区呢?
Q2:我怎么能检查缓冲区是否包含字符串的char * S1 =世界,你好!;
    我会需要搜索多个字符串。


解决方案

  1. 这将是更容易使用一个单一的一维数组。


  2. 的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.

解决方案

  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)

这篇关于是否字符数组包含字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆