Society of Robots - Robot Forum

Software => Software => Topic started by: BANE on September 11, 2010, 02:47:13 PM

Title: c programming
Post by: BANE on September 11, 2010, 02:47:13 PM
Hello all,

So I've always programed my robots in BASIC but i finally got myself into a C programming class this semester.  However, I'm having to start with "hello world" and no robots yet, which is probably a good thing lol. 
My question is: we use Microsoft Visual Studio 2006 in class but i have DEV C++ on my computer at home.  I've made sure that my source file type is in "C" and not "C++" before making a program but i keep on getting errors when compiling my programs at home.  Does anyone know if i have to change some settings or something to get DEV to act like Visual Studio? 

thnx in advance
Title: Re: c programming
Post by: ballbreaker on September 11, 2010, 03:22:58 PM
what kind of errors you got because i think for the simple programs its not different

if you don't get results on dev c++ like the program starts and finishes instantly use the getchar(); function at the end
Title: Re: c programming
Post by: greywanderer012345 on September 11, 2010, 06:36:53 PM
I used to use Dev-C++ because it was the best free compiler and IDE out there, and I had similar problems. Just in case you didn't know, Microsoft has a totally free version of Visual Studio. http://www.microsoft.com/express/Windows/ (http://www.microsoft.com/express/Windows/)
Title: Re: c programming
Post by: BANE on September 12, 2010, 05:51:05 AM
@ ballbreaker
Here is a pic of the error i've been getting when compiling and what it says        V
"7 C:\Users\JIF\Desktop\DCCC\C++\programming cd\Chapter3\Applications\A3_3.C `main' must return `int'"

@ greywanderer012345
thats really the only reason i have DEV because its free.  I'm going to check out your link here in a sec.
Title: Re: c programming
Post by: garrettg84 on September 12, 2010, 08:20:52 AM
"7 C:\Users\JIF\Desktop\DCCC\C++\programming cd\Chapter3\Applications\A3_3.C `main' must return `int'"

This simply means that your main program must return an integer.

instead of:
Code: [Select]
void main(void)
{
//code
}

you must have:
Code: [Select]
[b]int[/b] main(void)
{
//code
[b]return 0;[/b] //this is where you would return error codes in windows applications - zero denotes no problems
}

Your main program must 'always' return an integer. If you are not returning errors and nothing like that seems as if you'd need it, simply make it return 0. By the way, your style is very readable and it looks good, you must have had some good experience programming in the past. Though, there are no comments =).

-g
Title: Re: c programming
Post by: BANE on September 14, 2010, 09:32:20 AM
thnx g, i went ahead and downloaded Microsoft Visual C# 2010 from the link from greywanderer012345.  However, i still happen to be getting some errors.  I went ahead and uploaded a screen pic.  it doesn't seem to link my header
Title: Re: c programming
Post by: garrettg84 on September 14, 2010, 06:09:13 PM
I believe based on your program structure you should be looking for c++ or c, not C# (sharp). I have no experience with C# but based on a C# hello world, it looks as if everything must be class based more similar to the way Java is implemented.

http://www.csharphelp.com/2006/12/c-tutorial-for-beginners/ (http://www.csharphelp.com/2006/12/c-tutorial-for-beginners/)

If you were actually using C/C++ you would likely still need to put the 'include' statement as such:
Code: [Select]
#include <stdio.h>