Go to Post It would be a lot easier if students would quit being so magnificent. Really. - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 10-10-2003, 09:51
Tton Tton is offline
Registered User
#1089 (Team Mercury)
 
Join Date: Jan 2003
Location: Hightstown, NJ
Posts: 84
Tton is on a distinguished road
Send a message via AIM to Tton Send a message via Yahoo to Tton
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!
__________________
T-ton
  #2   Spotlight this post!  
Unread 10-10-2003, 10:30
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,817
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Here's a very simple program that counts input lines.

Code:
Main()    /*count input lines*/
{
	int c, nl;

	nl=0;
	while ((c = getchar()) != EOF)
		if (( c == ‘\n’)
			++nl;
	printf(“%d\n”, nl);
}
  #3   Spotlight this post!  
Unread 10-10-2003, 10:32
Yan Wang's Avatar
Yan Wang Yan Wang is offline
Ithaca is Gorges
AKA: John Wayne
FRC #0639 (Code Red Robotics)
Team Role: Alumni
 
Join Date: Sep 2002
Rookie Year: 2001
Location: Cambridge, MA
Posts: 1,910
Yan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud of
Send a message via ICQ to Yan Wang Send a message via AIM to Yan Wang Send a message via MSN to Yan Wang Send a message via Yahoo to Yan Wang
#include <stdio.h>

main()
{
for(;
{
printf ("Hello World!\n");
}
}
__________________
Code Red Robotics Team 639 Alumnus | www.team639.org
<Patrician|Away> what does your robot do, sam
<bovril> it collects data about the surrounding environment, then discards it and drives into walls
  #4   Spotlight this post!  
Unread 10-10-2003, 11:06
hobbes hobbes is offline
Registered User
#0058
 
Join Date: Oct 2003
Location: South Portland, Maine
Posts: 8
hobbes is an unknown quantity at this point
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<<".
  #5   Spotlight this post!  
Unread 10-10-2003, 11:19
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
Quote:
Originally posted by hobbes
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<<".
Saying that C++ is the next revision of C is a bit misleading. C++ is C with object-oriented extensions (as well as a few others). C is not being replaced by C++. There are many uses where C is much more appropriate to C++.

Matt
  #6   Spotlight this post!  
Unread 10-10-2003, 13:01
hobbes hobbes is offline
Registered User
#0058
 
Join Date: Oct 2003
Location: South Portland, Maine
Posts: 8
hobbes is an unknown quantity at this point
your right matt, rev was a bad choice of words.
  #7   Spotlight this post!  
Unread 10-10-2003, 22:27
djcapelis's Avatar
djcapelis djcapelis is offline
Fried Manic Custard
None #0675 (Geeks with Power Tools)
Team Role: Programmer
 
Join Date: May 2003
Rookie Year: 2001
Location: Rohnert Park, CA
Posts: 129
djcapelis will become famous soon enoughdjcapelis will become famous soon enough
Send a message via ICQ to djcapelis Send a message via AIM to djcapelis Send a message via Yahoo to djcapelis
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.
__________________
"I have more friends than enemies, I'm working to resolve the issue."
  #8   Spotlight this post!  
Unread 11-10-2003, 08:55
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Quote:
Originally posted by monsieurcoffee
#include <stdio.h>

main()
{
for(;;)
{
printf ("Hello World!\n");
}
}
I've not done console-C in a while, but I do believe it is actually:
Code:
#include <stdio.h>

int main(int argc, char *argv[])
{
   for(;;)
   {
        printf("Hello World!\n");
    }

   return 0;
}
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"

Last edited by Raven_Writer : 11-10-2003 at 09:02.
  #9   Spotlight this post!  
Unread 11-10-2003, 09:54
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
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.
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #10   Spotlight this post!  
Unread 11-10-2003, 10:19
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Quote:
Originally posted by Mike Betts
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....
Not to be nit-picky about this, but if you compiled monsieur's code, it wouldn't work because 1, main is not actually declared, and 2 main doesn't return a value (but that's only if you declare main to be an integer, and not void).
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #11   Spotlight this post!  
Unread 11-10-2003, 10:30
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
Quote:
Originally posted by djcapelis
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.
It only really becomes an issue when you're working with embedded controllers. C++ requires quite a bit more overhead than C does (well, many features of C++ do). This overhead is a very bad thing in a limited environment such as an embedded control. The other issue with C++ is portability. There are many more compliant C compilers out there than there are C++ compilers. These C compilers also run on many more different systems than C++ compilers. I will admit this is becoming a thing of the past but it's still something to consider.

Matt
  #12   Spotlight this post!  
Unread 11-10-2003, 12:54
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
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.
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...

Last edited by Mike Betts : 11-10-2003 at 12:58.
  #13   Spotlight this post!  
Unread 11-10-2003, 12:57
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Quote:
Originally posted by Mike Betts
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.
Sorry

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
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #14   Spotlight this post!  
Unread 11-10-2003, 14:11
djcapelis's Avatar
djcapelis djcapelis is offline
Fried Manic Custard
None #0675 (Geeks with Power Tools)
Team Role: Programmer
 
Join Date: May 2003
Rookie Year: 2001
Location: Rohnert Park, CA
Posts: 129
djcapelis will become famous soon enoughdjcapelis will become famous soon enough
Send a message via ICQ to djcapelis Send a message via AIM to djcapelis Send a message via Yahoo to djcapelis
Quote:
Originally posted by Mike Betts
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.

<snip>

Without adding this, Matt is unable to access command line parameters which is OK because we will not be running under DOS anyway...

Not exactly accurate, first, to comply with ANSI C Raven_Writer is correct in saying that main must return a value as ANSI C specifically says main must be declared as int.

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.)
__________________
"I have more friends than enemies, I'm working to resolve the issue."
  #15   Spotlight this post!  
Unread 11-10-2003, 22:21
Damian Manda's Avatar
Damian Manda Damian Manda is offline
The Damian
no team
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Fort Collins, CO
Posts: 154
Damian Manda has much to be proud ofDamian Manda has much to be proud ofDamian Manda has much to be proud ofDamian Manda has much to be proud ofDamian Manda has much to be proud ofDamian Manda has much to be proud ofDamian Manda has much to be proud ofDamian Manda has much to be proud ofDamian Manda has much to be proud of
Send a message via AIM to Damian Manda
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
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 15:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi