简体   繁体   English

搜索字符串

[英]Searching through string of characters

i have problem making program in which u could "draw" map using "S" as start "#" as route and "E" as end, and program would tell you the way. 我在制作程序时遇到问题,您可以使用“ S”作为开始,“#”作为路线,“ E”作为结束,来“绘制”地图,然后程序会告诉您方法。 Problem is that when i draw the map I'm not able to search throught characters in strings. 问题是当我绘制地图时,我无法搜索字符串中的所有字符。 here is sample of my wrong code that never finds the "S": 这是我找不到“ S”的错误代码的示例:

 char array[5][10];

 for(i=0;i<=5;i++){
     gets(array[i]);
 }

for(i=0;i<=5;i++){

    for(j=0;j<=10;j++){

       if(array[i][j]=="S"){
            printf("something");
       }
       else printf("something");
    }   
}

Your character comparison is incorrect 您的字符比较不正确

if(array[i][j]=="S"){

should become 应该成为

if(array[i][j]=='S'){

Double quotes "" enclose a string literal, not a character. 双引号""包含字符串文字,而不是字符。

Valid indexes in an array of size N in c++ are 0 upto N-1 . 在c ++中,大小为N的数组中的有效索引为0到N-1 In all your cycles you access elements 0 up to N . 在所有循环中,您访问元素0到N。 You access an out of bounds element and thus invoke undefined behavior. 您访问边界元素,从而调用未定义的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM