There are several issues with your code, as posted, but to answer the question you asked, you have:
char *major[] = {
"Electrical Engineering",
"Computer Engineering",
"Computer Science Engineering",
"Biomedical Engineering" };
In C++ a string literal, e.g.
"Electrical Engineering"
is a
constant, so has the type
const char *
. To get rid of the error message, use
const char *major[] = {
"Electrical Engineering",
"Computer Engineering",
"Computer Science Engineering",
"Biomedical Engineering" };
As noted, there are several issues with your code, but to me, the biggest issue is that you seem to be trying to use a strange mixture of C and C++. If you're going to be using C++, then you should probably use <iostream> (e.g. std::cout, std::cin) for console I/O, <fstream> for reading and/or writing files, and use a std::vector<student> to maintain the list of students, so you don't have to
realloc()
(which you are using incorrectly), the list as it grows.
What's the problem with
realloc()
? realloc returns NULL if it can't find the memory you need, so code like
array = (array_type *)realloc(array, newsize)
runs the risk of clobbering the good pointer to
array
that you did have, and replacing it with
NULL
. The block of memory you did have is now lost, as is all the data you stored there. The memory will stay "lost" until the program ends, when (usually), resources acquired by the program are released.