问题描述
因此,我开始尝试学习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);
解决方法
putchar()
中的“ s”代表“字符串”。您应该使用ZZEE1 <- kronecker((Z[,1] %*% t(Z[,1])),(E[,1] %*% t(E[,1])))
ZZEE2 <- kronecker((Z[,2] %*% t(Z[,2])),2] %*% t(E[,2])))
ZZEE3 <- kronecker((Z[,3] %*% t(Z[,3])),3] %*% t(E[,3])))
ZZEE4 <- kronecker((Z[,4] %*% t(Z[,4])),4] %*% t(E[,4])))
#...
ZZEE228 <- kronecker((Z[,228] %*% t(Z[,228])),228] %*% t(E[,228])))
ZZEE229 <- kronecker((Z[,229] %*% t(Z[,229])),229] %*% t(E[,229])))
来输出单个字符。
您的示例代码存在一些问题(不计算它不会编译的事实):
-
C字符串:一个零终止的字符数组
示例:
char[] mystring = "ABC";
是一个包含['A','B','C',0]
的4个字符的数组。 -
C字符串文字使用双引号(
"ABC"
); C字符文字使用单引号('A'
) -
printf采用STRING参数(双引号):
-
printf('%c',a1); // WRONG
-
printf("%c",a1); // CORRECT
-
-
puts()打印一个字符串
-
putchar()打印一个字符
我希望可以为您澄清一些事情:)