加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何使用scanf()而不包括stdio.h

发布时间:2020-12-16 03:22:58 所属栏目:百科 来源:网络整理
导读:是否有任何可能的方法来编写C程序而不包括stdio.h作为头文件.有人建议可以通过声明extern int scanf(char * format,…)来实现它; #include stdio.h //I want this same code to work without including this lineint main (){ char str [80]; scanf ("%s",st
是否有任何可能的方法来编写C程序而不包括stdio.h作为头文件.有人建议可以通过声明extern int scanf(char * format,…)来实现它;
#include <stdio.h> //I want this same code to work without including this line

int main ()
{
  char str [80];
  scanf ("%s",str);  
  return 0;
}

解决方法

您可以使用以下命令声明scanf函数:
extern int scanf(const char *format,...);

extern关键字是可选的,但我喜欢将其包含在内,以提醒函数在其他地方定义.

您的示例将如下所示:

extern int scanf(const char *format,...);

int main ()
{
  char str [80];
  scanf ("%s",str);  
  return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读