So I am working on this program for class to use a struct to make a student record with assigned values and then generalize the program so the user can enter their own data. I usually use Code:Blocks just because I'm used to it and my program runs fine on there. However, I ran it on Visual C++ 2010 and it will not run. The program specifies that a character array must be used (so no I cannot change it to a string even though that makes much more sense). Am I formatting the char array wrong? I looked up other examples of char arrays online and haven't been able to find why it is not working on Visual. Thanks in advanced for your help!
#include <iostream>
using namespace std;
struct StudentRecord
{
char Name[20];
int ID;
float GPA;
};
Sorry, forgot about that. It doesn't really say which part is wrong but { was only used in the struct and the char array and im pretty sure its the char array.
U probably forgot an = sign...but this wont work anyway as C style arrays cannot be assigned to. Don't forget that null char '\0' ! TESCStudent.Name{'S','u','p','e','r','P','r','o','g','r','a','m','m','e','r'};
U could do something like this:
1 2 3 4
char cmyName[] = "superprogrammer"; //null char is in there too
memcpy(TESCStudent.Name, cmyName, sizeof(cmyName));
TESCStudent.ID = 1234;
TESCStudent.GPA = 4.0;
Oh right, I have that right in my program I just must have deleted it when I was pasting it. It still won't work for some reason. (I'm editing it above to fix the assignment operator error)
You are wrong. It should work that is the member Name of the structure will be initialized and compiler will not issue any error. If you got an error then show it.