我有一个结构,我把所有关于球员的信息.那是我的结构:
struct player{
int startingCapital;
int currentCapital;
int startingPosition;
int currentPosition;
int activePlayer;
int canPlay;
};
Run Code Online (Sandbox Code Playgroud)
这是我的主要内容:
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
int main(int argc, char *argv[])
{ int s,i,numOfPlayers;
struct player *players;
printf("Give the number of players: \n");
scanf("%d",&numOfPlayers);
players = (struct player *)calloc(numOfPlayers,sizeof(struct player));
system("PAUSE");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我要求用户给出玩家数量,然后我尝试分配所需的内存.但我得到这个编译错误,我无法弄清楚:
invalid application of `sizeof' to incomplete type `player'
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习C中的指针并且正在编写这个小整数数组指针练习,但遇到了一个无效的sizeof类型int[]问题的应用程序.请告诉我哪里出错了以及如何解决.谢谢.
#include <stdio.h>
int intA[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int intB[];
void int_copy(const int *source, int *destionation, int nbr)
{
int i;
for(i=0;i<nbr;i++)
{
*destionation++ = *source++;
}
}
int main()
{
int *ptrA = intA;
int *ptrB = intB;
int sizeA = sizeof(intA);
int nbrA = sizeof(intA)/sizeof(int);
printf("\n\n");
printf("[Debug]The size of intA is:%d\n", sizeA);
printf("[Debug]That means the number of elements is:%d\n", nbrA);
printf("\n\nThe values of intA are:\n");
int i; …Run Code Online (Sandbox Code Playgroud)