home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

compiling C

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2829
Discussions: 200,969, Posts: 2,379,695, Members: 246,334
Old April 3rd, 2003, 07:50 PM   Digg it!   #1 (permalink)
is 4 f00t secks
 
sixf00t4's Avatar
 
Join Date: Aug 2002
Location: Da Burgh
Posts: 4,587
Blog Entries: 3
compiling C

http://www.techimo.com/forum/showthr...313#post613313 there is some C code in there. it wont compile for me in unix. anybody?
__________________
Music (4/15/08) - Video (4/15/08) - blog - Legend of Six RPG
sixf00t4 is offline   Reply With Quote
Old April 3rd, 2003, 08:22 PM     #2 (permalink)
dword to your moms
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 3,195
Send a message via AIM to krohnjw
That's C++ not c, you need to compile with a C++ compiler, ie g++
krohnjw is offline   Reply With Quote
Old April 3rd, 2003, 08:23 PM     #3 (permalink)
Senior Member
 
squeech's Avatar
 
Join Date: May 2002
Location: Rocky Mountain High
Posts: 613
The problem you're facing is that the C compiler you're using doesn't know the location of iostream.h. This is a header file that give the written program access to the statements like "cin" and "cout".

If you use the C++ compiler instead, you will not have this problem. Just enter g++ instead of gcc:

unixs1$ g++ test.c -o test
unixs1$ test

That should go more smoothly for you

~edit - blast! One minute too slow.
__________________
Talking in numbers doesn't make you smarter.
squeech is offline   Reply With Quote
Old April 3rd, 2003, 08:54 PM     #4 (permalink)
is 4 f00t secks
 
sixf00t4's Avatar
 
Join Date: Aug 2002
Location: Da Burgh
Posts: 4,587
Blog Entries: 3
(1) unixs1 $ g++ test.c -o test
test.c: In function `int main()':
test.c:19: name lookup of `a' changed for new ANSI `for' scoping
test.c:11: using obsolete binding at `a'
(2) unixs1 $ test
(3) unixs1 $

ok so it compiled that is one step, now is there some sort of switch of parameter to get the string in there?
sixf00t4 is offline   Reply With Quote
Old April 4th, 2003, 01:26 AM     #5 (permalink)
Senior Member
 
squeech's Avatar
 
Join Date: May 2002
Location: Rocky Mountain High
Posts: 613
The problem your getting now, assuming you copied the code EXACTLY like it was written in the post you linked to, is what's called a scope resolution error. When I retyped in the program to see if I could compile it, I automatically firxed that error out of habit and forgot I did so

Code:
#include <iostream.h>

int code[100];
char disp;


main()
{

     for(int a=0; a<=12; a++)
          {
               cout << "enter code \n";
               cin >> code[a];
          }

     cout <<endl<<endl;
//Look here, you'll notice I redeclared "a" as an int
     for(int a=0; a<=12; a++)
          {
	if(code[a]>22)
	{code[a]=code[a]-23;
		disp= code[a] + 64;}
	else{
		disp= code[a] + 68;}

	cout << disp << " ";

cout<<endl;

return 0;
}
The problem that shows up refers to line 19, which is after the comment I added. You'll notice in the code that I compiled, there is another "int" before "a=0". This is because right now, "a" is only scoped in the first "for" loop (located in line 11, which refers to the second line of the error).

So just try adding that "int" in front of a=0 in the second "for" statement (line 19)
squeech is offline   Reply With Quote
Old April 5th, 2003, 12:59 AM     #6 (permalink)
ILC
Senior Member
 
ILC's Avatar
 
Join Date: Oct 2001
Location: Eastern Shore
Posts: 701
Once the syntax errors are cleared, type:

cxx filename.cpp
a.out

This will compile the program using a unix c++ compiler, and than execute the program.

ILC
ILC is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3031)
Forty-six years ago today (12)
Breaking: San Diego ACORN Document .. (5)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
windows vista security holes (17)
Internet Lost (5)
windows 7 problem (7)
Is the PSU I received dead? (13)
Point and Shoot Camera Suggestions. (6)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Recent Discussions
Linksys WMP54GS wireless card problem.. (5)
windows vista security holes (17)
Help getting around port 80 for camer.. (5)
Skillsoft Network+ Study Software Que.. (10)
Browsers wont load websites (3)
Nvidia GTX 260 problem (2)
Delete an OS (8)
help me pls laptop just stopped worki.. (0)
Open With ..... Win7 (3)
Laptop with wireless problem. (12)
Internet Lost (5)
virus blocking exe. files (1)
Point and Shoot Camera Suggestions. (6)
CPU fan stops spinning randomly (11)
Modern Warfare 2: Who Bought It? (65)
Is the PSU I received dead? (13)
Print spooler problem (16)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
webcam (0)
upgrade for hp a6101 (0)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)


All times are GMT -4. The time now is 05:18 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



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