An Introduction To Programming Using C

A Member? Please Login  
type your username and password to login
Date: July 06, 2008, 11:21 PM
216497 members and 122195 Topics
Latest Member: mai-anguwa
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  An Introduction To Programming Using C
Pages: (1) (2) Go Down Send this topic Notify of replies
Author Topic: An Introduction To Programming Using C  (Read 2639 views)
qleyo (f)
Re: An Introduction To Programming Using C
« #32 on: September 24, 2006, 11:16 PM »

Quote
Though useful, note that "getch()" isn't ANSI standard. Even as a newbie, you should keep this in mind and try to write portable code as often as you can. Consider using "getc()" for reading in characters. But if the "getch()" functionality is what you really want, then it's ok. Read this too --> http://c-faq.com/osdep/cbreak.html

Not to sound cheeky C0dec, but I'm not sure if you've helped anyone there. I'm well aware of the limitations of getch, my using getch is mainly because of issues related to the compiler we are using for this tutorial - people have to figure out somethings themselves. I haven't really mentioned ANSI C throughout this tutorial, I've used the C language for PICs, DSPs, PCs and macs with native libraries (you can't really write portable embedded C code as its architecture dependent, additionally there a little hiccups when going between PCs and unix based machines) I'm trying to abstract what they should use C for so I don't put anyone in a box subconsciously (can be networking, CGI, embedded, windows native, mac native/cocoa (which is based on objective C) etc) I'm teaching concepts not stdio.h functions (eventually when we cover functions everyone will be able to look up a library and figure out what functions they would like to use - thats the idea) please avoid commenting in contradiction with the tutorial so as not to confuse anyone.

Quote
I also noticed you declared "char data" after calling the "puts()" function. This means your code will only compile with a C++ compiler and not a C compiler. In C, all function variables are declared first before functions, expressions, conditions etc are evaluated.

I know, but we are using a C/C++ compiler Wink - I'll have you know I no longer have a PC at my disposable (mac only, even at work we are all mac'ed out Wink ) and am writing these bits of code without compiling or running them (and having used OOP for quite a while I might have habits that compiler warnings would have helped avoid if you know what I mean).

Thanks.
c0dec (m)
Re: An Introduction To Programming Using C
« #33 on: September 25, 2006, 11:59 AM »

well just keep in mind that your audience might have access to other compilers and i just felt they should have some awareness of the ANSI standard. keep it up though. carry on.
alsimon
Re: An Introduction To Programming Using C
« #34 on: September 25, 2006, 01:45 PM »

hello  Qlayo,i was very impressed when i saw your programming language.i am a new person  in programming.i only want to seek your help.when doing web design with html,you save the file as .html.is it thesame in programming for instance,in ASP,BASIC do we save as .asp,.basic,.Hopin for your reply soon.bye Shocked
qleyo (f)
Re: An Introduction To Programming Using C
« #35 on: September 26, 2006, 01:31 PM »

Quote
well just keep in mind that your audience might have access to other compilers
At uni, if your code ran on another compiler and you brought it in and did not run on plato, you've failed execution marks. Its always good to have a standard. Once again I'm teaching concepts "using" the C language.

Quote
and i just felt they should have some awareness of the ANSI standard.
"Help"/"Advice" is always appreciated, just avoid sounding contradictory. You wouldn't "trust" your lecturer say in a physics class if a colleague of his walked in and went "that circuit will not run in any other country" say it was all designed at 50Hz because he chose. At the end of the day the equation hes trying to teach you will work irregardless of variables and so on. Once again sorry I'm not trying to sound cheeky, but you know what us programmers are like :p  - no one ever wins an argument because both cases have a degree of logic (especially with over 9 languages under my belt I'm afraid I can't help but think concept not syntax, for all I care I could write the function myself) 

For any inquisitive souls out there ANSI is an institution like IEEE, RF etc see http://en.wikipedia.org/wiki/Ansi and for ansi C http://en.wikipedia.org/wiki/ANSI_C
I own a copy of Kernigan and I advise you all (eventually) to try to get a copy in future - its like a bible.

Quote
when doing web design with html,you save the file as .html.is it thesame in programming for instance,in ASP,BASIC do we save as .asp,.basic,.
Alsimon, in a nutshell you're right (basic can be .sbl or. mod) asp is .asp there are quite a few others like in c, .h is a header file (you "include" this into a .c file) you can include a .c into a .c, but as you would imagine, it varies. For example web files are server dependent so you can configure a module (say like an online compiler) to handle each file type otherwise it'll treat it as text. I'll try not to open another can of worms and confuse you,  but eventually you'll find you can make your extension anything, and setup apache to parse it using the right modules. As you progress as an interactive developer (thats actually what I do for a living) you'll find HTML can be within anything, a php file, an asp file, .html, .htm and some people like me hide extensions and URLs from the client(your computer) altogether. One can then setup apache so the server sees the corresponding file name - for all i care I can make a file extension .qleyo but the server will see .php (the reason for this is orderliness and security by hiding extensions you have no idea what language I'm using). But in regards to your initial question, simply yes (extensions are just a standard).
naijafan (m)
Re: An Introduction To Programming Using C
« #36 on: September 29, 2006, 11:43 AM »

@TonyBlu
The codes i'm seeing here means you're really learning. Keep it up!
qleyo (f)
Re: An Introduction To Programming Using C
« #37 on: September 30, 2006, 03:58 PM »

Tutorial 5 - Loops

5.1 For loops
One of three loops C provides is the for loop. If you have a statement or a group of statements that need to be repeated a for loop is an easy way to implement.

The for loop format is similar in Basic and Pascal. The most common for is:
for ( initialisation ; conditional test ; action)

So the initialisation, that is the first thing you want the for loop to do, the first time it is called.
The conditional test is like an if statement, such that if that test is true the for loop continues to loop.
The action is what you want the for loop to do every time it loops.

Example
Say we wanted to count to 10 and every time we count we print the result to the screen.
First things first, we need a counter, we need to add one to this counter and print the result to screen until we reach 10.
Using a for loop this is how we would get it done


#include <stdio.h>

int main()
{
   //we declare our counter variable
   int i;

   for (i = 0; i < 11; i++)
   {
      printf ("Current count is - %d\n",i);
   }

  return 0;
}

Code explained

The only thing new to you here should be the for loop. Like the if statement the block of code falls within the curly brackets { }
The for loop starts by initialising (here we set i = 0, if we wanted to start counting from say 3, we would set i = 3) every time the for loop makes a loop it checks that i < 11 (i is less than 11, since we want to stop counting at 10) we could also use i <= 10 (i is less than or equal to 10)  to produce the same result. Lastly on each loop the action is performed i++ which is the same as i + 1. So each time the for loop runs we print the current value of i.

Try writing a for loop that decrements counting from 20 to 3 (not 3 to 20).

Picture of the result of my counter.


* count.jpg (35.9 KB, 608x326 )
adewaleafolabi (m)
Re: An Introduction To Programming Using C
« #38 on: October 12, 2006, 09:23 PM »

thnx qleyo for the loops. By the way i like your desktop theme looks like KDE
qleyo (f)
Re: An Introduction To Programming Using C
« #39 on: October 12, 2006, 11:07 PM »

No its not KDE its the standard mac os x interface Smiley - I do have linux (with KDE,gnome) on my PS2 but thats it.

note to all: after this tutorial things are really going to pick up (pace wise), so its important that you understand what we've covered so far.
chickalo
Re: An Introduction To Programming Using C
« #40 on: November 15, 2006, 09:20 PM »

Thanks qleyo,
          Thanks for this, its great. Does the tutor  in the compiler cover everything or one still needs to further his knowledge on bulky and discouraging books. Pleas where can I download Microsoft visual basic.
candylips (m)
Re: An Introduction To Programming Using C
« #41 on: April 25, 2008, 04:44 PM »

What happened to this thread. I guess qleyo got tired of programming as most females normally do after monkeying for a while.  Grin
 NIIT Students  Programming - What About Newbies Like Me?  .NET C#/VB.NET Project in the Pipeline for Programmers who may be interested  Page 2
Pages: (1) (2) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Jobs (2) Career Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.