Why not use a constructor for your class?
Code:
struct StudentRecord
{
StudentRecord() : ID(1234), GPA(4.0)
{
strcpy(Name, "SuperProgrammer");
}
char Name[name_size];
int ID;
double GPA;
};
Also why are you printing each individual character instead of just printing the string?
Code:
cout<<"Students Name: ";
for (int i=0; i<sizeof(str1)-1; i++) {
cout<<TESCStudent.Name[i];
}
cout << "Students Name; " << TESTCStudent.Name << endl;
There are a couple of things wrong with the way you're printing each character, first you're printing the entire array, which in this case has more characters than the string actually contains. In your example I wouldn't be surprised that you don't see characters that the user doesn't enter. You should be stopping at the end of the string not the end of the array. These could and usually are different numbers. For example if I entered "Jim" for the name the string length would be 3 and the size of the array would still be 20.
Oh and in the following snippet:
Code:
cin.getline(TESCStudent.Name,20,'\n');
You don't need that '\n' in this call, the '\n' is the default value.
Jim