尝试迭代并打印结构中的int **时出错

时间:2018-12-04 23:44:27

标签: c structure c99

尝试打印时收到的错误:

  

线程:wcsrtombs.c:94:__wcsrtombs:断言data .__ outbuf [-1] ==   '\ 0''失败。

     

已中止(核心已弃用)

extends layout

block content

  doctype html
  html(lang="en")
    head
      meta(charset='utf-8')
      meta(name='viewport' content='width=device-width, initial-scale=1')
    section
      nav
        ul
          li.title Study Bot
          li.robot 
            img(src='/images/robot-face.jpg' alt='Robot face' width='130px')
      article
    footer
      // Tab links
      .tab
        button.tablinks(onclick="openCity(event, 'London')") London
        button.tablinks(onclick="openCity(event, 'Paris')") Paris
        button.tablinks(onclick="openCity(event, 'Tokyo')") Tokyo
      // Tab content
      #London.tabcontent
        h3 London
        p London is the capital city of England.
      #Paris.tabcontent
        h3 Paris
        p Paris is the capital of France.
      #Tokyo.tabcontent
        iframe#encyclopedia-window(src='https://en.wikipedia.org/wiki/')
      script
        include ../routes/index.js

如何将int *放入称为游戏的结构的int **中。

token = strtok(dup, delim);

while( token != NULL ){
  if( game->size >= game->capacity ){
    game->layout = (int**)realloc(game->layout, game->capacity*2 * sizeof(int*));
    game->capacity = game->capacity * 2;
  }

  game->layout[game->size] = (int*)token;
  game->size = game->size + 1;
  token = strtok(NULL, delim);
}

我将打印内容更改为以下这段代码。我现在得到输出,没有错误,但是输出仍然是错误的。我认为可能正在打印内存。

for( size_t i = 0; i < game->size; i++ ){
  printf("%ls ", game->layout[i]);
  if(i == 0)
    continue;
  else if( (i+1) % 10 == 0 )
    printf("\n");
}

我的输出:

  

3276850 3276850 3276850 3276850 3276850 3276850 3276850 3276850   3276850 50 3276850 3538994 3538998 3604534 3604535 3604535 3473463   3473461 3276853 50 3276850 3604530 3604535 3604535 3276855 3276850   925958194 822097713 822097713 838874929 50 3276850 3276850 3276850   3276850 3276850 3276850 3276850 3276850 3276850 50 3670072 3670072   3539000 3538998 3538998 3735606 3735609 3735609 3276857 50 3276850   3276850 3276850 3276850 3276850 3276850 3276850 3276850 3276850 50   822095921 822095921 872427569 3407924 3735604 3735609 3735609 3276857   50 3276850 3276850 3276850 3276850 3276850 3276850 3276850 3276850   3276850 50 3342387 3342387 3538995 3538998 3538998 3735606 3735609   3735609 3276857 50 3342387 3342387 3538995 3538998 3538998 3735606   3735609 3735609 3276857 50 3276850 3276850 3276850 3276850 3276850   3276850 3276850 3276850 3276850 50

0 个答案:

没有答案