Получение ошибки "передача аргумента 2 из 'strcmp' делает указатель из целого числа без приведения", сравнивающего две строки - PullRequest
0 голосов
/ 12 февраля 2019

Я студент, и я пытаюсь завершить эту программу, его цель:

Распечатать данные продукта с тем же именем, что и запрошенное имя, на входе

Каждый раз, когда я пытаюсь скомпилировать программу, появляется это предупреждение:

warning: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast

#include <stdio.h>
#include <string.h>
#define N 100
#define M 8

int main (void) {
    int n;
    char name[N][M];
    char code[N][M];
    int price[N];
    char searchname;
    int i;
    int selection;
    int search, x;


    do {
        printf("Insert how many products to register: ");
        scanf("%d", &n);
    } while(n > N);

    for(i = 0; i < n; i++) {
        printf("Insert the name of the product n%d: ", i + 1);
        scanf("%s", name[i]);

        printf("Insert the code of the product registered: ");
        scanf("%s", code[i]);

        printf("Insert the price of the product registered: ");
        scanf("%d", &price[i]);
    }

    do {
        printf("Choose one of the following options:\n\n");
        printf("1) Print name and price of the searched product (code)\n");
        printf("2) Print the product that has the same name as the name inserted\n");
        printf("0) Close the program\n\n");
        printf("Type the number of the option: ");
        scanf("%d", &selection);

        switch(selezione) {
            case 1:
                x = 0;

                printf("Insert the code of the product: ");
                scanf("%d", &search);

                for(i = 0; i < n; i++) {
                    if(code[i] == search) {
                        printf("name: %s | price: %d\n\n", name[i], price[i]);

                        x = 1;
                    }
                }

                if(x == 0) {
                    printf("The searched code doesnt exist\n\n");
                }

            break;
            case 2:
                x = 0;

                printf("Insert the name to search: ");
                scanf("%s", searchname);

                for(i = 0; i < n; i++) {
                    while(strcmp(name[i], searchname) == 0) {
                        printf("Product number %d | Code: %s | Price: %d\n\n", i + 1, code[i], price[i]);
                        x++;
                    }
                }

                if(x == 0) {
                    printf("There are no products with this name\n\n");
                }

            break;
            case 0:
            break;
            default:
                printf("This option doesnt exist");
            break;
        }
    } while(selection!= 0);

    return 0;
}

Я некоторое время искал переполнение стека и сообщения, которыеупомянуть, что эта проблема бесполезна.
Что я пытаюсь сделать, это сравнить строку name[i] с searchname, которая тоже является строкой.
Я что-то здесь упустил?

1 Ответ

0 голосов
/ 13 февраля 2019

То, что я пытаюсь сделать, это сравнить строку name[i] с searchname, которая тоже является строкой.

char searchname; - не похоже на строку.- Евгений Ш.

Можно попробовать char searchname[100];… - Флюгер

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...