问题描述
因此,我开始尝试学习c(我来自python),而我以前学习python的一件事就是尝试用python制作井字游戏。因此,我认为我不妨尝试在c中打井字游戏。因此,我想首先用我的代码完成的工作是将井字游戏板上的每个位置存储为一个字符(将为0或X),然后确保我找到了一种方法来将其打印到终奌站。您可以在到目前为止的代码中看到这一点。 a1,a2和a3是顶部3,b1,b2和b3是中间3,c1,c2和c3是底部3:
a1 a2 a3
b1 b2 b3
c1 c2 c3
现在,我想确保我知道如何在命令行上打印井字游戏板的行,您可以在puts(a1); puts(a2); puts(a3);
的底部看到它。但是,当我运行该程序时,在终端中获得以下输出作为错误:
ticktacktoe.c:17:1: warning: parameter names (without types) in function declaration
char puts(a1); char puts(a2); char puts(a3);
^~~~
ticktacktoe.c:17:6: error: conflicting types for 'puts'
char puts(a1); char puts(a2); char puts(a3);
^~~~
In file included from ticktacktoe.c:1:0:
c:\mingw\include\stdio.h:677:41: note: previous declaration of 'puts' was here
_CRTIMP __cdecl __MINGW_NOTHROW int puts (const char *);
^~~~
ticktacktoe.c:17:1: warning: parameter names (without types) in function declaration
char puts(a1); char puts(a2); char puts(a3);
^~~~
ticktacktoe.c:17:21: error: conflicting types for 'puts'
char puts(a1); char puts(a2); char puts(a3);
^~~~
In file included from ticktacktoe.c:1:0:
c:\mingw\include\stdio.h:677:41: note: previous declaration of 'puts' was here
_CRTIMP __cdecl __MINGW_NOTHROW int puts (const char *);
^~~~
ticktacktoe.c:17:1: warning: parameter names (without types) in function declaration
char puts(a1); char puts(a2); char puts(a3);
^~~~
ticktacktoe.c:17:36: error: conflicting types for 'puts'
char puts(a1); char puts(a2); char puts(a3);
^~~~
In file included from ticktacktoe.c:1:0:
c:\mingw\include\stdio.h:677:41: note: previous declaration of 'puts' was here
_CRTIMP __cdecl __MINGW_NOTHROW int puts (const char *);
^~~~
我也尝试按照printf('%c',a1);
的方式使用printf函数,但这似乎也不起作用。这是我当前的代码,任何帮助将不胜感激:
#include<stdio.h>
#include<string.h>
//these are the variables for what is displayed on the tic tac toe board
char a1 = '0';
char a2 = '0';
char a3 = '0';
char b1 = '0';
char b2 = '0';
char b3 = '0';
char c1 = '0';
char c2 = '0';
char c3 = '0';
puts(a1); puts(a2); puts(a3);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)