Trying to compile - errors

Good Day all....

What I have is a soccer game source code (it is a text based game) - I want to make some changes to the code and change some of the features.... Now here are the problems

It is .cpp code and I am trying to compile it as it is (no modifications) I am doing this to see if there are any errors in the existing code before trying to modify...

I am getting 3 errors and 158 warnings - Most of the errors are :

warning: deprecated conversion from string constant to 'char*' (with the line of error noted)

the errors are:

In function 'void get_ref_data()'error: name lookup of 'i' changed for ISO 'for' scoping note: (if you use '-fpermissive' G++ will accept your code)

In function 'void run_extratime()'error: 'cin' was not declared in this scope

In function 'int Get_Attendance(int)'error: 'cin' was not declared in this scope


Now I am a complete newbie - I am trying to teach myself as I go along but could maybe use some help pointing me in a solution direction... I am not asking anybody to do the work for me but maybe just see if someone can help me find out how to solve the issue (in plain english) - I have looked the errors and such up but I cannot understand what is being said (above my head).....

I have posted the code on Codepad here:

http://codepad.org/wXIZ1837 (I have not included the header files as they seem to not be the problem yet - but I can if needed)

I can post the error log as well if needed...

Again any help or guidance would be greatly appreciated

Thank You in advance
Well, I hope, I'd be able to explain...^^

The first four errors were that there was a comment beginning (/*) already inside of a comment. The adequate code lines are these ones:
(lines 21 to 26)

1
2
3
4
5
6
/**********************************************************************/
/*   @ESMS.CPP
/*
/*   The game running file
/*
/**********************************************************************/


If I'm right, you have to end the comment at each line if you want to 're-start' it every line. So your code should look like this:

1
2
3
4
5
6
/**********************************************************************/
/*   @ESMS.CPP   */
/**/
/*   The game running file   */
/**/
/**********************************************************************/


See the comment endings (*/) at the end of each line? If they miss, the compilet complains about a comment within a comment. =)

So this is done. But there are also 2 more errors and one warning.
The 'first' error is about your #include "game.h" . I don't know if you compiled the source code as itself or within a project. Anywy this error means that the compiler could not find a file named like this. If you have the header file in anoher directory than the working directory, you have to say this to the compiler. E.g. in DEV-C++ you have to hit ALT+P or go by the menu to "Project -> Project Options". Then to the tab "Directories", in there to "Include Direcories" and there youenter the path of the directory your header is in.
The warning is that you ignore the #pragma wrning . If the compiler says that, he's almost everytime right. So only delete this line from your source code and then, the copiler should not complain abut that.
The 'second' error is abut the fact that you have an array named team[2] and it's of the data value struct teams. If you don't code, what this teamsthing is, you will not achieve any progress. Also, if you defined teams in game.h, you don't have to write struct teams. A single teams is ok =)

If you have any questions, ask them.
@others: If you have any suggestions for improvement, let me know this =)
Last edited on
To your other errors:

In function 'void get_ref_data()'error: name lookup of 'i' changed for ISO 'for' scoping note: (if you use '-fpermissive' G++ will accept your code)

In function 'void run_extratime()'error: 'cin' was not declared in this scope

In function 'int Get_Attendance(int)'error: 'cin' was not declared in this scope


To the second and third error named in your post above, it's mentioned that the compiler doesn't know cin. The compiler needs a std::cin. I'm not really sure, but I guess this std:: means that the compiler should look up the following argument in stdlib. As already mentioned, I'm not really sure about this, but it's right. To clear these errors, you have to use either using namespace std; at the beginning of your cpp-file or you have to use std::cin everytime you use cin. I prefer using the first one in every source file, but if you don't want to, you don't want to =).

If I interpret the first error right, it means that you are changing i where you are not allowed to. I myself would try to find some other soultion having the same result as i--; but at the moment I don't really know what to do... =(
closed account (z05DSL3A)
In function 'void get_ref_data()'error: name lookup of 'i' changed for ISO 'for' scoping note: (if you use '-fpermissive' G++ will accept your code)
This would mean that the code has something like:

1
2
3
4
5
6
for(int i = 0; i < some_value; i++)
{
    // do somthing here
    // i is in scope
}
int x = i;  // here i is being used out of scope according to ISO changes 


you could change the code or use the compiler switch '-fpermissive' mentioned.
Grey Wolf is right. It's in line 1047: int temp = random(i-1); I'd give you a better version of your get_ref_data:

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
void get_ref_data()
{
	FILE *refdat;
	char buffer[300];
//	int strictness[150], used[150];
	char refsname[150][50], strictness[150][10], used[150][10];
	refdat = fopen ("referees.dat", "r");
    if (refdat == NULL)
    {
        printf("\nError. Failed to open referees.dat file\n"),
        EXIT(1);
    }
	fgets(buffer, 299, refdat);

        int t;

	for (int i = 1; i <= 150; i++)
	{
		if (fgets(buffer, 155, refdat) == NULL)
			break;

			int ret = sscanf(buffer, "%s %s %s", refsname[i],
				strictness[i],
				used[i]);

			if (ret != 3)
				i--;
                 t=i;

	}
	int temp = random(t-1);
	temp++;

	strcpy(refname, refsname[temp]);
	refstrict = atoi (strictness[temp]);
	fclose(refdat);
}
I altered the random(i-1) into random(t-1) and implemented t as an int before the loop and inside I defined t as i. At all, it has the same effect as our solution.
So this is done. But there are also 2 more errors and one warning.
The 'first' error is about your #include "game.h" . I don't know if you compiled the source code as itself or within a project. Anywy this error means that the compiler could not find a file named like this. If you have the header file in anoher directory than the working directory, you have to say this to the compiler. E.g. in DEV-C++


Thank You - as far as Game.h - I have that saved (and will post to copy pad)

http://codepad.org/BM43SzF3 <--- there it is (and it is in the same directory - the reason it said it could not be found is because YOU did not have it ) :)
@FlashDrive: That's redundant. Why make a spare variable 't' that just copies 'i' 150 times, if you can just move 'i' a scope up?

1
2
3
int i;
for (i = 1; i <= 150; ++i) { // Loop stuff }
int temp = random(i-1);
oh, I understand. The errors are from codepad, aren't they?
The 'first' error is about your #include "game.h" . I don't know if you compiled the source code as itself or within a project. Anywy this error means that the compiler could not find a file named like this. If you have the header file in anoher directory than the working directory, you have to say this to the compiler. E.g. in DEV-C++ you have to hit ALT+P or go by the menu to "Project -> Project Options". Then to the tab "Directories", in there to "Include Direcories" and there youenter the path of the directory your header is in.


The game.h file is in the same folder - it was an error for you as you did not have it... I have posted it to Codepad
http://codepad.org/BM43SzF3

I also noticed it needed playerroster.h

http://codepad.org/tYGP78cq



Topic archived. No new replies allowed.