Hello! I was making simple programm for word search, but found an error I can't explain.
This code piece of code that causes it is:

                if (word==search){
                    printf("\n %i %s ", i, word);
                    i++;
                             }

I can only suppose that the compiler(visual studio express) dosn't support such comparisions of sth should be done about the array's sizes.

#include <stdio.h>
#include <conio.h>

void main() {
    FILE *f;
    int i = 1;
    char word[20];
    char name[20];
    char search[20];
    printf("Please input the mane of the file: ");
    scanf("%s", name);
    if((f=fopen(name, "r"))==NULL) {
        printf("Error");
        getch();
                return;
    }
    printf ("\nPlease input the word for search: ");
    scanf("%s", search);
    while (!feof(f)) {
    fscanf(f, "%s", word);
        if (word==search){
        printf("\n %i %s ", i, word);
        i++;}
    }
    fclose(f);
    getch();
}

Edited 3 Years Ago by Dani: Formatting fixed

That is right you can directly compare C style string using ==. You need to use the library function strcmp

Edited 6 Years Ago by Banfa: n/a

Thenks a lot for strcmp, now it works.

ps: but then another question:) If it's ok to use == in C, why it gives me an error?

Sorry that's a typo on my part should have read

"you can't directly compare C style string using =="

Edited 6 Years Ago by Banfa: Correcting the correction

This question has already been answered. Start a new discussion instead.