Dynamically changing array elements inside of structures

I'm learning pointers and references in class and I have run across what I believe to be a syntax problem which I don't understand. I have a structure with two character array and I need to be able to change the size of those array dynamically. But I have no idea how to do that. Take a look at my code and tell me what I am doing wrong.
I have to use character arrays and I think the dot notation. I am not sure if I can use arrow notation. I can not do this problem using strings and vectors.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <cstring>

using namespace std;

struct Student
{
	char* firstName;
	char* lastName;
	float gpa;
	
};

Student createStudentRecord()
{
	char FN[20], LN[20];
	float gpa;
	cout << "Enter first name";
	cin >>FN;
	cout << "\n Enter last name";
	cin >> LN;
	cout << "\n Enter GPA";
	cin >>gpa;
		
	int FNSize = strlen(FN);
	int LNSize = strlen(LN);

	Student* studentRecord = new Student;
	studentRecord.firstName = new char[FNSize];

}
As student record is a ponter, you have to either dereference it first ((*studentRecord).firstName), or use pointer member selection: studentRecord->firstName
Do I have to put the 'char' before (*studentRecord).firstName like I did on the line above. I ask because in the line above I have to put the data type but elsewhere on the web I've seen this type of line work without the data type
You need to put data type when you are declaring (creating) valuable. In all other cases you do not need it. You don't write std::istream cin >> char[20] LN, do you?
I got it, thanks for helping out
Topic archived. No new replies allowed.