Linux compile issue

I've created my code in Microsoft Visual Studio Express 2013 and it compiles and runs fine. I've moved this over to Linux and had compile errors. To fix it, I had to add in #include <cstring> on my student.h file and it compiles fine. However now it does not give me the correct input. Is there a difference between the strcmp and strncpy in Linux? Or am I missing a step to make it work on Linux?

student.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 #ifndef STUDENT_H
#define STUDENT_H

#include <iostream>
#include <cstring>
using namespace std;

class Student
{
public:
	Student(const char initId[], double gpa);
	bool isLessThanByID(const Student& aStudent) const;
	bool isLessThanByGpa(const Student& aStudent) const;
	void print()const;
private:
	const static int MAX_CHAR = 100;
	char 	id[MAX_CHAR];
	double	gpa;
};
#endif 


student.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "student.h"


//implement the required 3 functions here


Student::Student(const char initId[], double gpa) : gpa(gpa)
{
	// initialize a newly created student object with the passed in value
	strncpy_s(id, initId, Student::MAX_CHAR - 1);
	id[Student::MAX_CHAR - 1] = '\0';
	
	
}

bool Student::isLessThanByID(const Student& aStudent) const
{
	//  compare the current student object with the passed in one by id.
	if (strcmp(id, aStudent.id) > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
	
	
}

bool Student::isLessThanByGpa(const Student& aStudent) const
{
	// compare the current student object with the passed in one by gpa
	if (gpa < aStudent.gpa)
	{
		return true;
	}
	else
	{
		return false;
	}
	
}

void Student::print() const
{
	cout << id << '\t' << gpa << endl;
}


app.cpp
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
#include "student.h"

int main()
{
	Student s1("G10", 3.9);
	Student s2("G20", 3.5);

	s1.print();
	s2.print();

	if(s1.isLessThanByID(s2))
	{
		cout << "about right!" << endl;
	}
	else
	{
		cout << "uhmm ..." << endl;
	}
	if(!s1.isLessThanByGpa(s2))
	{
		cout << "about right!" << endl;
	}
	else
	{
		cout << "uhmm ..." << endl;
	}

	//system("pause");
	return 0;
}
This seems like a good question but in order to get better feedback you should move this file to the LINUX/UNIX questions instead of the beginners questions that way you and others can get help
isLessThanByID() returns true if the ID of this has a greater lexicographical ordering than the parameter.
Topic archived. No new replies allowed.