Add to Favorites
Hosting Discussion
 

forgot password?


Reply


Old
  Post #1 (permalink)   05-21-2004, 06:30 AM
HD Wizard
 
Join Date: Aug 2003
Posts: 1,003

Status: gooooogle is offline
Hi. I've spent the last few days learning c programming and today I realised that I actually learned quite a bit. Bellow is the code for a program I made without refering to any form of refrence. I just did it from the top of my head.

Quote:
#include <stdio.h>

main()
{
int birth_year, required_year, result;
printf("What year were you born?: ");
scanf("%d", &birth_year);
printf("What year do you want to know your age for?: ");
scanf("%d", &required_year);
result = required_year - birth_year;

if (result < 0)
printf("You were not born in %d", required_year);
else if (result == 0)
printf("You were born in %d", required_year);
else
printf("In the year %d you will be %d years old", required_year, result);

printf("\n");
return 0;
}
It's not much but it's something.
 
 
 


Old
  Post #2 (permalink)   05-27-2004, 01:13 PM
HD Master
 
Join Date: Apr 2004
Location: London, UK
Posts: 366

Status: imported_HadleyHost is offline
Looks good - Good luck with anything else that you do
__________________
Mark Uttley
Email: mark@hadleyhost.com
http://www.hadleyhost.com
Good quality webhosting solutions for fantastic prices!
 
 
 


Old
  Post #3 (permalink)   05-27-2004, 03:10 PM
HD Master
 
Join Date: Mar 2004
Location: Stanwood, WA
Posts: 294

Status: FatalSw1tch is offline
ahhhh the good old days. I took VB / C / C++ in high school 10th grade stuff. IT is very very similar to PHP. I am suprised for just a few hours how clean your coding looks. Keep it clean if you continue makes it so much easer for Debugging . Oh and don't forget to comment everything lets you know what you are doing
 
 
 


Old
  Post #4 (permalink)   05-28-2004, 03:51 AM
HD Wizard
 
Join Date: Jul 2003
Posts: 2,100

Status: BlackStorm is offline
I have never done C programming, have seen it a lot though.
Your code is very clean looking and laid out very well, you would be surprised how much that helps when you are looking through it either for a problem or just looking at what code is there.

I don't really comment my code unless it is needed for someone else looking at it, the reason is I normally know what the code is used for anyway after I do it, and adding the comments just takes more time when I don't need it myself.

It is a good idea if you think you might forget what you were doing (Can happen a lot when you start using advanced code and writing code which uses a lot of lines for the one function)

Looking good so far
 
 
 


Old
  Post #5 (permalink)   05-28-2004, 08:29 AM
HD Master
 
Join Date: Mar 2004
Location: Stanwood, WA
Posts: 294

Status: FatalSw1tch is offline
John you always comment code in a project. Incase you can't work on it for a while and forget what you were trying to create
 
 
 


Old
  Post #6 (permalink)   05-28-2004, 08:41 AM
HD Wizard
 
Join Date: Jul 2003
Posts: 2,100

Status: BlackStorm is offline
Hehe I have a project which I have been working on for at least 18 months with tens of thousands of lines of code.
I would have about 100 lines of comments and thats it.

Just too much to comment everything when there is so much code to write, when you have to code until the early morning you just couldn't be bothered having to do more work than needed hehe

I always know what I was doing through from just looking at what the code is, like if I saw someone elses code with comments, I would still know what they are doing
 
 
 


Old
  Post #7 (permalink)   05-31-2004, 01:13 PM
Dom
 
Posts: n/a

Status:
Out of interested, where did you start learning it from?
Was it from a site?Or a book?
 
 
 


Old
  Post #8 (permalink)   05-31-2004, 01:49 PM
HD Wizard
 
Join Date: Aug 2003
Posts: 1,003

Status: gooooogle is offline
I started learning from a book my dad has called "The C programming Language" by Brian W. Kernighan and Dennis M. Ritchie. A good book.
 
 
 


Old
  Post #9 (permalink)   06-01-2004, 06:58 AM
HD Master
 
Join Date: Feb 2004
Posts: 253

Status: imported_Stephen is offline
Weren't you learning another programming language too?
Not sure but thought I remembered seeing you saying about doing another language too
 
 
 


Old
  Post #10 (permalink)   06-01-2004, 07:04 AM
HD Wizard
 
Join Date: Aug 2003
Posts: 1,003

Status: gooooogle is offline
I read about lots of languages. The other one I'm currently doing is RealBasic from RealSoftware.
 
 
 


Old
  Post #11 (permalink)   06-01-2004, 02:36 PM
HD Wizard
 
Join Date: Aug 2003
Posts: 1,003

Status: gooooogle is offline
I just rewrote it in RealBasic. Here is the result.

Quote:
// declare all strings and doubles
dim birth_year, new_year, result_year As String
dim birth_yearint, new_yearint, result_yearint As double

birth_year = edfBirth.text
new_year = edfNewYear.text

// convert strings to doubles for calculations
birth_yearint=cdbl(birth_year)
new_yearint=cdbl(new_year)
result_yearint=cdbl(result_year)

result_yearint = new_yearint - birth_yearint

//convert back to string for displaying
result_year=cstr(result_yearint)
new_year=cstr(new_yearint)

lblResult.text = result_year + " years old"
lblResult.visible = true
I will post a screenshot of it running.
 
 
 


Old
  Post #12 (permalink)   06-01-2004, 02:38 PM
HD Wizard
 
Join Date: Aug 2003
Posts: 1,003

Status: gooooogle is offline
Here it is running on Mac OS X. RealBasic can also compile for Windows and Linux but I just happened to be using my Mac at the time.
Attached Images
File Type: jpg running.jpg (4.8 KB, 6 views)
 
 
 


Old
  Post #13 (permalink)   06-01-2004, 03:00 PM
HD Wizard
 
Join Date: Aug 2003
Posts: 1,003

Status: gooooogle is offline
And here is an advertising campaign for RealBasic.
Attached Images
File Type: jpg evolvetitle.jpg (88.4 KB, 19 views)
 
 
 


Old
  Post #14 (permalink)   06-12-2004, 07:41 AM
HD Newbie
 
Join Date: Jun 2004
Posts: 24

Status: diginode is offline
What you need to learn to become a C programmer is pointers and how the C program is compiled into assembly. C does not have any sort of automatic memeory management. You need to allocate buffers for strings and other data. If you get memory managment wrong, you'll either end up with memory leaks or a big gaping security hole. To understand why, you have to understand how declared varibles are situated in the stack, and various other low-level things.
__________________
::. www.diginode.net : Dedicated / VM Servers .::
::. Instant Remote Reboot & OS Installs : Secure Console Access .::
::. Over 20 OS to choose from : Install a new OS everyday .::
 
 
 


Old
  Post #15 (permalink)   08-25-2004, 10:42 AM
HD Newbie
 
Join Date: Aug 2004
Posts: 16

Status: Thermit is offline
C is the best language that I've ever used, and I've done quite a few. It's a like a Ferrari with no seatbelts: incredibly powerful, but if you make a mistake it could get ugly. Many languages borrow from C syntax too, so it's quite useful...
__________________
Money Talk | Webhosting Forum
 
 
 
Reply

Thread Tools

New Post New Post   Old Post Old Post
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On