이 배열이 인쇄되지 않는 이유에 대한 힌트를 줄 수 있습니까? 내 인쇄 기능에 어떤 문제가 있는지 알지 못합니다. 내 코드에 다른 부분을 추가하기 전에 올바르게 작동하는지 확인하고 싶습니다. 나는 배열을 올바르게 설정하지 않았다고 추측하고있다. 왜냐하면 아무것도 인쇄하지 않는 이유가 바로 &이다.사용자 입력 배열 인쇄
#define NUMSTU 50
#include <stdio.h>
//function prototype
void printdata();
//Global variables
int stuID[NUMSTU];
int stuCount;
int totStu;
int main()
{
int stuCount = 0;
int totStu = 0;
int studentID;
//Prompt user for number of student's in class
printf("Please enter number of student's in class:");
scanf ("%d", &totStu);
for (stuCount = 0; stuCount <totStu; stuCount++)
{
//Prompt user for student ID number
printf("\n Please enter student's ID number:");
scanf("%d", &studentID);
stuID[NUMSTU] = studentID;
}
//Call Function to print data
printdata();
return 0;
}//end main
void printdata(){
//This function will display collected data
//Input: Globals stuID[NUMSTU]
//Output: none
//Display column headers
printf("\n\n stuID\n");
//loop and display student ID numbers
for (stuCount = 0; stuCount <totStu; stuCount++){
printf("%d", stuID);
}
}
'stuID [NUMSTU] = studentID; '는 정의되지 않은 동작을합니다. 범위를 벗어난 요소를 쓰고 있습니다. – melpomene
'printf ("% d", stuID);'에는 정의되지 않은 동작이 있습니다. 'printf''% d'은'int'를 취합니다,하지만 당신은'int *'를 넘겨주고 있습니다. – melpomene
'totStu'라는 두 개의 변수가 있습니다. 그 중 하나만 0이 아닌 값을가집니다. – melpomene