Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,333 members, 7,811,973 topics. Date: Monday, 29 April 2024 at 03:25 AM

An Introduction To Programming Using C - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / An Introduction To Programming Using C (9220 Views)

An Introduction To PHP - Beginners Base / Plz Can Anyone Solve This Using C++? / I Need Help On Oop Project Using C# Console-base Application (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: An Introduction To Programming Using C by qleyo(f): 11:16pm On Sep 24, 2006
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.

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.

1 Like

Re: An Introduction To Programming Using C by c0dec(m): 11:59am On Sep 25, 2006
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.
Re: An Introduction To Programming Using C by alsimon: 1:45pm On Sep 25, 2006
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 [b].asp,.basic,.[/b]Hopin for your reply soon.bye shocked
Re: An Introduction To Programming Using C by qleyo(f): 1:31pm On Sep 26, 2006
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.

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.

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).
Re: An Introduction To Programming Using C by naijafan(m): 11:43am On Sep 29, 2006
@TonyBlu
The codes i'm seeing here means you're really learning. Keep it up!
Re: An Introduction To Programming Using C by qleyo(f): 3:58pm On Sep 30, 2006
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.

Re: An Introduction To Programming Using C by adewaleafolabi(m): 9:23pm On Oct 12, 2006
thnx qleyo for the loops. By the way i like ur desktop theme looks like KDE
Re: An Introduction To Programming Using C by qleyo(f): 11:07pm On Oct 12, 2006
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.
Re: An Introduction To Programming Using C by chickalo: 9:20pm On Nov 15, 2006
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.
Re: An Introduction To Programming Using C by candylips(m): 4:44pm On Apr 25, 2008
What happened to this thread. I guess qleyo got tired of programming as most females normally do after monkeying for a while. grin
Re: An Introduction To Programming Using C by tallibee(m): 3:48pm On Jan 05, 2010
gleyo you are too much!!! i can design a website for u where u can do all these conviniently if u dont mind. cheer
Re: An Introduction To Programming Using C by Hadampson(m): 12:09pm On Feb 22, 2019
Kudos to you Qleyo

(1) (2) (Reply)

How Do You Get A CEH / Pentesting Job In Nigeria? / Android Quiz Application With Json Parser, Php And Mysql Database / C++ Or Java: Which Way To Go?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 33
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.