Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 功能预订三维座位_C - Fatal编程技术网

C 功能预订三维座位

C 功能预订三维座位,c,C,我需要创建一个函数,允许我在表中保留位置。该表是三维数组 Tabblock[30][5][100] 30块;5级;100个座位 但像这样的董事会是一个更大的“分割错误”。我尝试创建这样的结构: char tabbloc[33][5][10] = {} ; int i = 0 ; int numblocares = 0 ; for (i=0 ; i < 33 ; i++ ) { for(i = 0 ; i < 5 ; i++)

我需要创建一个函数,允许我在表中保留位置。该表是三维数组

Tabblock[30][5][100]

30块;5级;100个座位

但像这样的董事会是一个更大的“分割错误”。我尝试创建这样的结构:

  char tabbloc[33][5][10] = {} ;  
  int i = 0 ;
  int numblocares = 0 ; 

    for (i=0 ; i < 33 ; i++ )
    {
        for(i = 0 ; i < 5 ; i++)
        {
            for (i = 0 ; i<100 ; i++)
            {
                tabbloc[i][i][i] = "libre" ; 
                printf("%s", tabbloc[i][i][i]); 

            }
        }
    } 
char tabbloc[33][5][10]={};
int i=0;
int numblocares=0;
对于(i=0;i<33;i++)
{
对于(i=0;i<5;i++)
{

对于(i=0;i如果我理解正确,您实际上想要如下所示:

#include <string.h>
#include <stdio.h>

int main()
{
    char tabbloc[33][5][100] = {} ;  
    int numblocares = 0 ; 
    
    for (int x=0 ; x < 33 ; x++ )
    {
        for(int y = 0 ; y < 5 ; y++)
        {
            strcpy(tabbloc[x][y],"libre"); 
            printf("%s", tabbloc[x][y]); 
        }
    } 
   ... 
   return 0;
}

您需要在每个循环签名中使用不同的索引变量,而不是在所有循环中使用相同的
i
变量

请注意,对于给定的
tabbloc
结构(即
char tabbloc[33][5][100]
),必须使用将字符串复制到给定位置。由于
strcpy
具有签名:

char* strcpy(char* destination, const char* source);

您不需要最后一个循环,只需传递存储在
tabbloc[i][j];

中的char*,如果我理解正确,您实际上需要如下内容:

#include <string.h>
#include <stdio.h>

int main()
{
    char tabbloc[33][5][100] = {} ;  
    int numblocares = 0 ; 
    
    for (int x=0 ; x < 33 ; x++ )
    {
        for(int y = 0 ; y < 5 ; y++)
        {
            strcpy(tabbloc[x][y],"libre"); 
            printf("%s", tabbloc[x][y]); 
        }
    } 
   ... 
   return 0;
}

您需要在每个循环签名中使用不同的索引变量,而不是在所有循环中使用相同的
i
变量

请注意,对于给定的
tabbloc
结构(即
char tabbloc[33][5][100]
),必须使用将字符串复制到给定位置。由于
strcpy
具有签名:

char* strcpy(char* destination, const char* source);
您不需要最后一个循环,只需传递存储在
tabbloc[i][j];