【发布时间】:2018-01-31 11:56:50
【问题描述】:
当我尝试编译时收到警告,我无法解决这个问题。你们能帮帮我吗?谢谢。
警告:初始化从没有强制转换的指针生成整数 [-Wint 转换] char ch = NULL; ^
这里是我的代码:
#include <stdio.h>
#include <string.h>
#include "order.h"
void readInts(int* ptr1, int*ptr2, int*ptr3, char* ptrChar);
int main(void)
{
int p1, p2, p3;
char ch == NULL;
readInts(&p1, &p2, &p3, &ch);
if (ch == 'A')
{
printf("%s\n", "Ascending3");
printf("%s %d %d %d\n", "Before swap: ", p1, p2, p3);
ascending3(&p1, &p2, &p3);
printf("%s %d %d %d\n\n", "After: ", p1, p2, p3);
}
else if (ch =='B')
{
printf("%s\n", "Descending3");
printf("%s %d %d %d\n", "Before swap: ", p1, p2, p3);
descending3(&p1, &p2, &p3);
printf("%s %d %d %d\n\n", "After swap: ", p1, p2, p3);
}
return 0;
}
void readInts(int* ptr1, int* ptr2, int* ptr3, char* ptrChar)
{
printf("%s\n", "Enter 3 numbers: ");
scanf("%d %d %d", ptr1, ptr2, ptr3);
printf("%s\n", "Enter a character A&B");
scanf(" %c", ptrChar);
}
【问题讨论】:
-
你认为
char ch == NULL;的声明是做什么的?空字符和NULL指针有什么区别? -
char ch == NULL;(==错字为=)-->char ch = 0; -
欢迎来到 Stack Overflow。请注意,在这里说“谢谢”的首选方式是投票赞成好的问题和有用的答案(一旦你有足够的声誉这样做),并接受对你提出的任何问题最有帮助的答案(这也给出了你的声誉小幅提升)。请查看About 页面以及How do I ask questions here? 和What do I do when someone answers my question?