简体   繁体   English

在为2D数组分配空间时,程序卡住了

[英]Programm is stuck while allocating space for a 2d array

Hey guys I have a problem, I i need to allocate space for a 2d array, but it somehow gets stuck. 嗨,我有一个问题,我需要为2D数组分配空间,但不知何故卡住了。 Afterwards it should get into a for loop, but it never gets there. 之后,它应该进入for循环,但永远不会到达那里。 Does someone has an idea why? 有人知道为什么吗?

  int len = read_file("staedte.csv", staedte, laender, bewohner);

  char **resultat;
  int resultatzaehler = 0;
  resultat =(char **) malloc (100 * sizeof(char));
  if(resultat == NULL){
    printf("Malloc failed to allocate space");
    exit(1);
  }
  for(int i = 0; i < 100; i++){
    resultat[i] =(char *) malloc (100);
    if(resultat[i] == NULL){
      printf("Malloc failed to allocate spacce 2");
      exit(1);
    }
  }

You should be allocating by using 您应该通过使用进行分配

resultat = (char**) malloc(100 * sizeof(char *))
for(i = 0; i < 100; i++) {
resultat[i] = (char*) malloc(100 * sizeof(char))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM