-1

我正在用 C 编程并用 gcc 编译。每次编译时,我都会收到一个堆栈粉碎检测到的错误。这是什么意思,我该如何解决?

#include <stdio.h>

#define MAX_ARRAY 50


static int getScore(int assignmentNum[], int weight[], int daysLate[], float score[]){

  int position, tempWeight, tempLate;
  float tempScore;

  scanf("%d %f %d %d", &position, &tempScore, &tempWeight, &tempLate);
  score[position] = tempScore;
  weight[position] = tempWeight;
  daysLate[position] = tempLate;
  assignmentNum[position] = position;
  return weight[position];
}


int main(void){

  int penalty_points,  num_drop, num_assignment;
  static int assignmentNum[MAX_ARRAY], daysLate[MAX_ARRAY], weight[MAX_ARRAY];
  static float score[MAX_ARRAY];
  char statGen;
  int total = 0;

  scanf("%d %d %s", &penalty_points, &num_drop, &statGen);
  printf("%d\n", penalty_points);

  while (total <  100) {
    total = total + getScore(assignmentNum, weight, daysLate, score);
  }    
  return 0;
}
4

1 回答 1

6

你使用%swith &statGen。说明%s符用于字符串;相应的参数必须指向一个为字符串提供足够空间的缓冲区,包括一个终止空字符。不过,statGen是单人char

要仅读取单个char,请使用"%c"代替"%s"。如果要跳过字符前的空格,请使用" %c". 该空间要求scanf跳过空白。

于 2013-09-27T14:13:54.190 回答