C语言 如何将 两字符串的比较结果 作为 if 的判断条件

例如我有兩個字符串

 char i[9][13], j[13];

应该如何正确地將 i[2(或由前面的语句提供的一个数作)] ==(或!=) j 作为 if语句的判断条件?(或!=)
我试过

 if(strcmp(i[n], j) !=0)   //string.h

 if(i[n]!=j)

上面两个if代码片段都嵌套与一个for代码块,n由for提供
程序都没办法正确执行这个if判断,而是直接跳过了if代码块,执行下面的语句

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

FILE *input_file, *output_file;

int total_people, giving_to, accepting, having[9], money_counter;

char giver[9][13], receiver[9][13], the_giver[13], the_recever[13];

int people_scaner, people_judger;



int test_count;

int main () {
    input_file = fopen("gift1.in", "r");
    output_file = fopen("gift1.out", "w+");

    fscanf(input_file, "%d\n", &total_people);

    //read all name to a array called `giver[][]` and `receiver[][]`
    people_scaner = 0;

    while(people_scaner < total_people){
        fscanf(input_file, "%s", giver[people_scaner]);
        /*
         *&giver[people_scaner] = &receiver[people_judger];
         */
        people_scaner ++;
    }

    //read the first of who giving gift to others to `the_giver`
    fscanf(input_file, "%s", the_giver);

    //if the guy who is the first person on the list of `giver[]` eles increase the people_judger
    people_judger = 0;

    if(strcmp(the_giver, giver[people_judger]) != 0){
        people_judger ++;
    }


    //according to the number of last step, scan next two number to &having[people_judger] and giving_to, giving_to will be resuing 
    fscanf(input_file, "%d%d", &having[people_judger], &giving_to);
    accepting = having[people_judger] / giving_to;

    for(people_scaner = 0; people_scaner < giving_to; people_scaner++){
        //read a recever
        fscanf(input_file, "%s", the_recever);
        printf("%s\n", the_recever);
        //put the gift from the giver to the recever
        people_judger = 0;
        if(strcmp(the_giver, giver[people_judger]) != 0){       //这里
            people_judger++;
            printf("%d\n", people_judger);
            continue;
        }
        having[people_judger] = accepting + having[people_judger];

        people_scaner++;
    }

    fclose(input_file);
    fclose(output_file);
    return 0;
}

所读文件

5
dave
laura
owen
vick
arm
dave
200 3
laura
owen
vick
owen
500 1
dave
arm
150 2
vick
owen
laura
0 2
arm
vick
vick
0 0

题目来源
USACO Greedy Gift Givers

int strcmp(char *str1,char *str2);
字符串比较函数
str1 str1=str2 返回0
str1>str2 返回正数

这是C语言的字符串,不能直接比较,C++的string类型,可以直接比较。

if(strcmp(str[0],str[1])>0)类似这样

str1 str1=str2 返回0
str1>str2 返回正数

不等于就是结果不是0,就行了

查一下strcmp,strncmp,和其他字符串库函数,以后就不会碰到这种问题了

如果我是要求不等于是要使用两次strcmp然后将它们的结果&&起来吗?
是的

直接調用 strcmp函數,頭文件string.h