我是一名学生,我正在努力完成这个程序,他的目标是:
打印输入中与请求名称同名的产品数据
每次,当我尝试编译程序时,都会出现此警告:
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
也是字符串的字符串进行比较。
我在这里错过了什么吗?
我想做的是将字符串
name[i]
与searchname
也是字符串的字符串进行比较。
char searchname;
- 看起来不像字符串。– 尤金 sh。
你可以试试char searchname[100];
…… – 风向标
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句