Please take a look at this code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//Tells computer when ARRAY_SIZE is used to automate 100
#define ARRAY_SIZE 30
int main(void){
//int grade[ARRAY_SIZE];
int *grade;
char continueResponse; //Y/N
int count = 0;
int i; //loop conditional variable
//allocates memory for the data
grade =malloc(sizeof(int) * ARRAY_SIZE);
if(grade == 0){
exit(1); //return 1;
}
printf("This program will create a list of your grades.\nPress ENTER after each grade.\n\n");
//input loop
for(i = 0; i < ARRAY_SIZE; i++)
{
printf("Enter grade percentage(0-100) [%02d/%02d]: ", i+1, ARRAY_SIZE);
scanf("%d",&grade[i]); //caps the inputs to array size of 30
count++; //count=count + 1; increments to next position in array
printf("Continue? (Y/N): ");
scanf(" %c",&continueResponse);//reads response
if(continueResponse != 'Y' &&continueResponse != 'y')
{
printf("\n == Grade Book ==\n\n");
break;//break out of for loop
}
}
printf("Grades entered: \n");
for(i = 0; i < count; i++){
printf("\t%d\n", grade[i]);
}
free(grade);
return 0;
}
What is this section doing? How/why is the "1" variable there?
Code:
if(grade == 0){
exit(1); //return 1;