问题描述
我不明白为什么我在尝试编译时总是出现错误。我收到一条错误消息
I don't understand why I keep getting an error when I try to compile it. I get an error saying
fractions.c:在函数 main中:
fractions.c:35:24:警告:赋值使整数从没有强制转换的指针开始[默认启用]
fractions.c:38:24:警告:赋值从没有强制转换的指针开始整数[b]
fractions.c:41:24:警告:赋值从没有强制转换的指针使整数[默认启用]
fractions.c:44:24:警告:赋值从没有强制转换的指针使整数[默认启用]
fractions.c:48 :11:警告:未使用的变量 fArray [-Wunused-variable]
fractions.c: In function "main":
fractions.c:35:24: warning: assignment makes integer from pointer without a cast [enabled by default]fractions.c:38:24: warning: assignment makes integer from pointer without a cast [enabled by default]fractions.c:41:24: warning: assignment makes integer from pointer without a cast [enabled by default]fractions.c:44:24: warning: assignment makes integer from pointer without a cast [enabled by default]fractions.c:48:11: warning: unused variable "fArray" [-Wunused-variable]"
#include <stdio.h>
#include <stdlib.h>
typedef struct{
int numerator;
int denomonator;
char operator;
int num2;
int den2;
} fraction;
void printFraction(fraction f);
int main(){
fraction myFraction;
char input;
printf("Enter the numerator of fraction 1: ");
scanf("%i", &myFraction.numerator);
printf("Enter the demoninator of fraction 1: ");
scanf("%i", &myFraction.denomonator);
printf("Enter the numerator of fraction 2: ");
scanf("%i", &myFraction.num2);
printf("Enter the demoninator of fraction 2: ");
scanf("%i", &myFraction.den2);
printf("\n\nEnter the operation you would like to perform\n");
printf("(1) for addition\n(2) for subtraction\n(3) for multiplication)");
printf("\n(4) for division\n");
scanf("%c", &input);
switch(input){
case '1':
myFraction.operator = "+";
break;
case '2':
myFraction.operator = "-";
break;
case '3':
myFraction.operator = "*";
break;
case '4':
myFraction.operator = "/";
break;
}
fraction fArray[] = {myFraction};
printFraction(myFraction);
return 0;
}
void printFraction(fraction f){
printf("%i/%i %c %i/%i\n", f.numerator, f.denomonator, f.operator, f.num2, f.den2);
}
推荐答案
这是字符串文字(ISO C99 6.4.5):
This here is a string literal (ISO C99 6.4.5):
"+"
您想要一个字符常量(ISO C99 6.4.4.4):
You want a character constant (ISO C99 6.4.4.4):
'+'
这篇关于为什么编译器会发出“警告:赋值从指针进行整数转换而不进行强制转换”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!