Vexing: Not declared in scope. Done this a thousand times on windows.

I have used this type of decleration many, many, many times in C++ and C# for Windows. For some reason gcc-c++ has a problem with the scope of the variable. What can I do with this? Thank you to all you kind souls that answer all my dumb questions. Merry Christmas!

login as: root
root@184.106.180.133's password:
Last login: Tue Dec 21 01:49:27 2010 from cpe-76-172-220-236.socal.res.rr.com
[root@dsgfedora01 ~]# cd ..
[root@dsgfedora01 /]# ls
bin boot cgroup dev dsgsports etc home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var
[root@dsgfedora01 /]# cd dsgsports
[root@dsgfedora01 dsgsports]# ls
downloadtribune downloadtribune.cpp loaddsgsports loaddsgsports.cpp
[root@dsgfedora01 dsgsports]# g++ -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlpp -L/usr/lib/mysql -L/usr/local/lib/mysql++ loaddsgsports.cpp -o loaddsgsports
loaddsgsports.cpp: In function âint main()â:
loaddsgsports.cpp:108:20: error: âoutputâ was not declared in this scope
[root@dsgfedora01 dsgsports]#



int main()
{
mysqlpp::Connection conn(false);

if (conn.connect("dsgsports","127.0.0.1" , "root", "")) {
printf("Connected to database.\n");
}
else {
printf("Failed to connect to database.");




return 1;
}

FILE *pFile;
pFile = fopen("/tmp/headend.txt","r");

if(pFile != NULL)
{
int cnt=0;
int i=0;
char curLine[1000];

while((fgets(curLine,1000,pFile))!=NULL)
{
std::cout << output[cnt] << endl;
cnt++;
}
rewind(pFile);
char output[cnt][1000];

while(i<=cnt)
{
fgets(output[i], 128, pFile);
cout << output[i] << endl;
truncate(output[i]);
i++;
}
fclose(pFile);
}
else
{
std::cout << "Could not open file.\n" << endl;
}

outputToImport("aa","aa", &conn);
return 0;
}
I'm sure you already know it's a syntax error, right?

Please use code formating tags for code.
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
int main()
{
	mysqlpp::Connection conn(false);

	if (conn.connect("dsgsports","127.0.0.1" , "root", "")) {
		printf("Connected to database.\n");
	}
	else {
		printf("Failed to connect to database.");
		return 1;
	}

	FILE *pFile;
	pFile = fopen("/tmp/headend.txt","r");

	if(pFile != NULL)
	{
		int cnt=0;
		int i=0;
		char curLine[1000];

		while((fgets(curLine,1000,pFile))!=NULL)
		{
			std::cout << output[cnt] << endl;  // output used here
			cnt++;
		}
		rewind(pFile);
		char output[cnt][1000];    // output declared here

		while(i<=cnt)
		{
			fgets(output[i], 128, pFile);
			cout << output[i] << endl;
			truncate(output[i]);
			i++;
		}
		fclose(pFile);
	}
	else
	{
		std::cout << "Could not open file.\n" << endl;
	}

	outputToImport("aa","aa", &conn);
	return 0;
}
Topic archived. No new replies allowed.