Hello,
I have a question about comparing strings.
First, I will post the code I've written:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void make_word(char* s, char c)
{
int len = strlen(s);
s[len] = c;
s[len + 1] = '\0';
}
int main()
{
char grid [3][4] = {{'a', 'b', 'c'},
{'d', 'e', 'f'},
{'g', 'h', 'i'}};
char word[] = "abc";
char found_word[] = ""; //room for found_word
int i;
for(i = 0; i != 3; i++)
{
make_word(found_word, grid[i]);
}
if(word == grid[3])
{
printf("yes");
}
return 0;
}
So what I am trying to do is to compare two strings.
In the code, there is an array grid and a string found_word.
The string found_word is made from the array grid.
The function allows the grid to become a string.
So what I have done is make the 'a' 'b' 'c' into a string "abc", which is same as "abc" from the string word.
So now the word contains "abc" and found_word also contains "abc"
However, when I try the if loop, they are not the same.
How do I make the array and the string the same so that when the if loop runs, it prints the "yes"?
Please help