如何比较两个字符串,它们(两个)都存储在char双指针中?

时间:2016-11-02 07:46:43

标签: c

/* *** INTERFACE *** */
    .interface {
        position: absolute; right: 2.16vw;
        width: 29.04vw;
        transition: top 2s, right 2s, width 2s, height 2s;
    }

    #content.leftHand .interface {
        right: 68.8vw;
    }

    #content.vertical .interface {
        top: 68.8vh !important;
        height: 29.04vh !important;
    }

    .interface > div {
        position: absolute; top: 0; bottom: 0; left: 0; right: 0;
        width: 27.94vw;
        margin: auto;
        transition: height 2s, width 2s;
    }

    #content.vertical .interface > div {
        height: 27.94vh !important;
    }

    #settings {
            top: 2.09vh;
            height: 10.15vh;
        }

        #content.vertical #settings {
            right: 3.29vw;
            width: 10.15vw;
        }

        #content.vertical.leftHand #settings {
            right: 86.57vw;
        }

        #settingsContainer {
            height: 8.65vh;
        }

        #content.vertical #settingsContainer {
            width: 8.65vw;
        }

        #settingsContainer div {
            width: 100%; height: 100%;
            margin: 0; padding: 0;
        }

        #settings span {
            position: absolute; top: 0.52vh; display: block;
            width: 5.2vw; height: 7.61vh;
            transition: top 2s, left 2s, width 2s, height 2s;
        }

        #settings button {
            position: absolute;
            width: 100%; height: 100%;
            cursor: pointer;
            border: 0;
                background-color: rgba(230, 0, 225, 1);
            transition: opacity 1.5s;
        }

        #content.vertical #settings span {
            left: 0.52vw !important;
            width: 7.61vw; height: 5.2vh;
        }

        /* SwitchHand & Rotate */           
            #switchHandBtn {
                left: 0.32vw;
            }

            #content.leftHand #switchHandBtn {
                left: 22.4vw;
            }

            #content.vertical #switchHandBtn {
                top: 0.32vh;
            }

            #content.leftHand #switchHandBtn:not(:hover) #rightHandBtn, #content:not(.leftHand) #switchHandBtn:not(:hover) #leftHandBtn,
            #content.leftHand #switchHandBtn:hover #leftHandBtn, #content:not(.leftHand) #switchHandBtn:hover #rightHandBtn {
                opacity: 0;
            }

            #rotateBtn {
                left: 5.84vw;
            }

            #content.leftHand #rotateBtn {
                left: 16.88vw;
            }

            #content.vertical #rotateBtn {
                top: 5.84vh;
            }

            #content.vertical #rotateBtn:not(:hover) #rotateHorBtn, #content:not(.vertical) #rotateBtn:not(:hover) #rotateVertBtn,
            #content.vertical #rotateBtn:hover #rotateVertBtn, #content:not(.vertical) #rotateBtn:hover #rotateHorBtn {
                opacity: 0;
            }

现在我想将存储在赎金中的字符串与杂志进行比较。怎么做?请帮忙

1 个答案:

答案 0 :(得分:2)

您可以在循环中使用strcmp

for (i = 0; i < n; i++) {
    if (strcmp(magazine[i], ransom[i]) == 0) {
        ...
    }
}

但如果(如标题所示)ransom被声明为指向char的指针:

char **ransom;

您不希望取消引用运算符*

*ransom = malloc(sizeof(char*) * n);

应该是

ransom = malloc(sizeof(char*) * n);