![]() |
Can I get an example of?
I want to see a simple code in C so i can look how it all is. This year im learning C++ and wanted to see what it looks like!
|
Here's a very simple program that counts input lines.
Code:
Main() /*count input lines*/ |
#include <stdio.h>
main() { for(;;) { printf ("Hello World!\n"); } } |
you'll find that C looks very similar to C++ (as it should, it is the next rev of C, hence the "C++"), although you will not be able to use some common C++ functions like "cin >>" and "cout<<".
|
Quote:
Matt |
your right matt, rev was a bad choice of words.
|
I would argue otherwise, there are no places that c++ cannot do just as well as c, seeing as it's almost completely backwards compatable... just because the new features are there, doesn't mean you've got to use them.
|
Quote:
Code:
#include <stdio.h> |
Both codes will work...
Raven_Writer's code requires two passed parameters at invocation... argc (an integer) and argv(a pointer to an array of characters (also known as a string)). However, neither is used by the function "main". monsieurcoffee's code is more traditional and correct as a stand alone program. However, he needs to indent his code so that it is more readable... Without indenting, any non-trivial code is very hard to maintain. Both Matt and djcapelis are correct but (IMHO) Matt's mindset is more correct for this project... C is a subset of C++, however, using C++ for the PIC processor (if you could) would be like hanging a picture with a sledgehammer. It can be done if you are very careful but, chances are, you will hit your thumb a few times quite unnecessarily. Code for the robot should be simple and elegant with static variable structures. There is absolutely no need for C++ and all the excess baggage it brings with it. |
Quote:
|
Quote:
Matt |
Eric,
I did compile and run Matt's code under Turbo C and Quick C with no problems. His program is the simplest code which is guaranteed to run under ANSI compliant C. see http://www.lysator.liu.se/c/simple-c Now to correct an error I made... Your example is valid under DOS, etc... In your code argc is a integer which is the number of command line parameters and argv is a pointer to an array of pointers to arrays of characters. These strings are the command line parameters entered by you when you run the executable. see: http://www.lysator.liu.se/c/multiple-level Without adding this, Matt is unable to access command line parameters which is OK because we will not be running under DOS anyway... As I said... Your code also works... I did not mean to start a fight here. Peace. |
Quote:
I'm still stuck on PC-coding, and forgot about the point, which was to discuss the new language's syntax. You didn't start a fight, it was me that forgot for about 3 hrs. what this was actually about ;) |
Quote:
As for command line parameters, they aren't just for DOS... if so they'd be useless... that command line sucks. They are also the same to access command line parameters on UNIX type operating systems. (Which if these Micro controllers were running BrickOS we theorectically might care about, but then again, they aren't.) |
As posted in the Programming Help thread, this site provides many examples of C programming: http://computer.howstuffworks.com/c.htm
There are more examples and explanation there than we could possibly post. --Damian Manda |
| All times are GMT -5. The time now is 13:59. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi