c - 我正在尝试打印电话号码,但出现错误
问题描述
只是为了让你们都知道我在编程方面很新,我想我只是错过了一些小东西,但我不知道它是什么。当我编译我的代码时,我收到此错误“格式%d
需要一个匹配的int
参数 [ -Wformat=
]”。我已经尝试了很多东西。我已经尝试将所有函数类型char
都设置为int
. 我得到类似的错误。
char *phoneInput(void)
{
char phone[11];
printf("Input the politicians phone number with no spaces: ");
fgets(phone, 10, stdin);
return 0;
}
char printPhone(char phone[11])
{
printf("- Phone Number: (%d%d%d)%d%d%d-%d%d%d%d", phone[0], phone[1], phone[2],
phone[3], phone[5], phone[6], phone[7], phone[8], phone[9]);
return 0;
}
解决方案
您的printf
陈述缺少另一个论据。添加phone[4]
到您的printf
喜欢这个。
#include <iostream>
using namespace std;
char *phoneInput(void)
{
char phone[11];
printf("Input the politicians phone number with no spaces: ");
fgets(phone, 10, stdin);
return 0;
}
char printPhone(char phone[11])
{
printf("- Phone Number: (%d%d%d)%d%d%d-%d%d%d%d", phone[0], phone[1], phone[2],
phone[3], phone[4], phone[5], phone[6], phone[7], phone[8], phone[9]);
return 0;
}
但我不明白的是,为什么你所有的函数都有一个返回类型,char*
或者char
实际上来自两个函数,你只返回一个0
。
推荐阅读
- r - 使用 append() 和 get() 形成列表列表
- angular - 在组件中获取对象时未定义对象
- java - GeoTools 中的 OpenStreetMap 图层
- python - 如何在 Python Pillow 中设置字体的字距?
- emacs - 书签文件无法保存在 Emacs 中
- python - 尝试将数据拟合到 SARIMA 时,Nonetype 对象不可迭代
- java - 如何从相应的 xsd'S 获取自己的 xml 编辑器的信息?
- python - 如何将两个图像序列应用于模型的输入?
- c# - 为什么 MonoDevelop 和 Unity3D 不知道 Application.LoadLevel();?
- typescript - 打字稿如何键入一个代理它的道具并注入一个道具