Can i change the array's rows length after i define it as constant or any other way?
Can you under my code or explanation?

#include<stdio.h>

#define CLASS_SIZE 20 //First define the array rows's length

void main()
{
	double gpa, average, highest, lowest;
	int student, rows, i, j;
	char grade[CLASS_SIZE][5]; //Wish to change the CLASS_SIZE

	printf("Enter the number of student : ");
	scanf("%d", &CLASS_SIZE); //Can i change the arrays length after declared ?

	for(j=0;j<CLASS_SIZE;j++)   //What should i modify?
	{
		printf("\nStudent No.%d :\n", j+1);

		for(i=0;i<5;i++)
		{
			printf("Enter subject %d's grade : ", i+1);
			fflush(stdin);
			scanf("%c", &grade[j][i]);
		}
	}

	printf("+===========+=============================+\n");
	printf("|           |             SUBJECT         |\n");
	printf("|  STUDENT  +=============================+\n");
	printf("|           |  1  |  2  |  3  |  4  |  5  |\n");
	printf("+===========+=============================|\n");
	for(j=0;j<rows;j++)
	{
		printf("|     %d     |", j+1);
		for(i=0;i<5;i++)
		{
			printf("  %c  |", grade[rows][i]);
		}
		printf("\n");
	}
	printf("+===========+=============================+\n");
}

There is realloc(), but it's not available for declared arrays, just allocated ones. But you can malloc or calloc a new array, and then transfer the old, into the new array, yourself. Doing it yourself, gives you a better chance at understanding the process - good for a student. No doubt realloc() is handy, of course, so maybe you want to start out with an allocated array, instead of a declared one?

From the Pelles C help file:

Purpose:
Changes the size of an allocated object.

Syntax:
void * realloc(void *ptr, size_t size);

Declared in:
<stdlib.h>

Description:
The realloc function deallocates the old object pointed to by ptr and returns a pointer to a new object that has the size specified by size. The contents of the new object shall be the same as that of the old object prior to deallocation, up to the lesser of the new and old sizes. Any bytes in the new object beyond the size of the old object have indeterminate values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.