Jump to content

C lesson #1--First C


Recommended Posts

The computer is fool and doesn't know anything before or after 0,1 so we need to compile every program to convert it in machine code.Don't go that much deep you'll understand these things automatically.So for every C program you wrote you need to complie it using a compiler use ant compiler i recommend Code::Blocks compiler best interface..!

Ok we start with here..!!

every C program has a starting point and end point denoted with {(start) and }(end) and every program has a main function too..!

SO we will write a program which will print First C on the screen..

Void main()

{

}

this is a primilary start to get structure of program.

Now we will add a function printf which is used o print things in screen

void main()

{

printf("first C");

Now you guys were asking why i pt ; after end?Answer is ; is used to denote that our line is ended..! if we will pu that it will give an error while compiling..!

But guys this program too will not print the First c and will give errors .

REASON:As i told you in starting computer is fool he doens't know what is printf we need to understand computer whats printf so we will show him the codes which were used to make printf so we will include a header(source code)file in the program itself..

#include <stdio.h>

void main()

{

printf("First C");

}

Here #include <*> is syntax and * is the name of the file here stdio.h(*.h extension of file) is the name of the file which has source code for printf function.

But guys now it will print First C but an unusual error we will face that screen will apper and than goes off in less than a second so for that we will use another function which will hold the screen till user says.

#include <stdio.h>

void main()

{

printf("First C");

getch();

}

the name of function is getch and syntax is getch() and same here ; will be used to denote that line has been ended

Now too we won't be able to see First C written in output screen as we missed an important thing that is computer is fool and doens't know whats getch..! we will include its header(source) too

#include <stdio.h>

#include <conio.h>

void main()

{

printf("First C");

getch();}

Conio.h is the name of the file which contains the source of getch function..!

and Finall we will see the out put as First C in screen but weird;y wwe will face another problem thats  out put would be like this

First CFirst CFirst CFirst CFirst CFirst CFirst CFirst C

something like this what we observed that first C should be printed one or say it was prnted once but old screen didn't got cleared so we will add another function clrscr which will clear previous screen before printing anything now its like this

#include <stdio.h>

#include <conio.h>

void main()

{

clrscr();

printf("First C");

getch();

}

Now we wil get the output w/o any errors and problems wait# didn't any query raised in your mind?

If no.. than rethink again please before reading..!

Query should be:I said PC is fool and didn't know anything and hence it didn't knows that whats clrscr so we have to show him header of it But wait again i sad it will show first C w/o problem

REASON:-Conio.h contains the source code of clrscr function too..!

Ok guys test it yourself you can print anything in screen we will be back in C by c lesoon #2 ASAP  :)

Link to comment
Share on other sites

  • 2 weeks later...

There's a slight mistake in your tutorial. Its not mandatory to have a main() function in every program. A program can run even without a main function.

But why are you using conio.h header? Its not part of the standard C Language. That header is specific to Turbo C++. No modern compiler has it.

dude try tch w/o conio.h it will not work and my teacher said getch function ka header file is conio.h And even scanf too uses conio.h(maybe)And dude every compiler supportds it u can see any program by me has conio.h And every compiler supports it..!
Link to comment
Share on other sites

dude try tch w/o conio.h it will not work and my teacher said getch function ka header file is conio.h And even scanf too uses conio.h(maybe)And dude every compiler supportds it u can see any program by me has conio.h And every compiler supports it..!

No scanf uses stdio.h.

And no conio.h is not present any modern compiler i have used till now. It is not even a part of ISO or ANSI or POSIX.

And yes getch() is in conio.h but we dont use that function nowadays.

Link to comment
Share on other sites

There's a slight mistake in your tutorial. Its not mandatory to have a main() function in every program. A program can run even without a main function.

But why are you using conio.h header? Its not part of the standard C Language. That header is specific to Turbo C++. No modern compiler has it.

C\C++ program without main() :rofl: :rofl:

its like a man without nervous system

visual studio 2010 has conio.h.

Link to comment
Share on other sites

@crackUC

why don't you switch over to c++. its more easy and advanced at the same time

Dude i payed the teacher money for C and he said C shoud be leanred before c++.But now i realised what he was 50-50% Means what he said was also right and its converse is also right that no need of learning c before c++ but i have some books too its clearly written in them too C should be learned before c++..And i didn't even finished c file handling pointers and many other things still left..!
Link to comment
Share on other sites

Dude i payed the teacher money for C and he said C shoud be leanred before c++.But now i realised what he was 50-50% Means what he said was also right and its converse is also right that no need of learning c before c++ but i have some books too its clearly written in them too C should be learned before c++..And i didn't even finished c file handling pointers and many other things still left..!

c++ is actually an extension of c. every concept of c is repeated in c++
Link to comment
Share on other sites

c++ is actually an extension of c. every concept of c is repeated in c++

true that i saw when i able to understood c++ program written on board.! but still i feel many people say this learn C before c++ reason (i actually don't need).I will learn c++ @ home myself after C..!
Link to comment
Share on other sites

use ivor horton's book for c++

never heard of that but ok if u said it may be the best book i'll search if its available here or not after if not i'll oder online ..! i have let us C book by yashwant kanetkar.I was thinking to buy the same book of c++ too okay that i'll decide later not know lemme first learn C completely I shall may not learn C++ and learn visiual basic instead...! or JAVa most probly VB coz i somehow make me sometm away from programmimg And i'm learning flash script base now with C..!
Link to comment
Share on other sites

not possible. they will compile but not run.

main() is like a brain. it coordinates every module of your program.

Dude the program will compile and run also without main(). You just have to know how to do it.

then start using some good ones

Well both of them are excellent compilers. And in office i work in a linux environment most of the time so GCC and Eclipse are the best. And later on when you join a software company you'll see you wont need those console input functions any more. I hardly ever use them.

Link to comment
Share on other sites

what are those?Explain a bit dude..! and see this

Nowadays all programs are GUI based you take input from the GUI and not from the console(command prompt). So these console input related functions and console related header files are almost never used in the industry.

And as for your screen shot, you didn't write main() so it didn't work. You can use a pragma directive if you want to write programs without main(). Or you can use a shadow main() using #define or you can also use the start string and use compiler switches to compile correctly.

Link to comment
Share on other sites

Nowadays all programs are GUI based you take input from the GUI and not from the console(command prompt). So these console input related functions and console related header files are almost never used in the industry.

And as for your screen shot, you didn't write main() so it didn't work. You can use a pragma directive if you want to write programs without main(). Or you can use a shadow main() using #define or you can also use the start string and use compiler switches to compile correctly.

But dude some old functions were really usefull like gotoxy i still didn't found any alternate for it ..IF i want to orientate a program in c that how will i do that?
Link to comment
Share on other sites

But dude some old functions were really usefull like gotoxy i still didn't found any alternate for it ..IF i want to orientate a program in c that how will i do that?

You wont need gotoxy while developing real life applications. Like i said gotoxy works only in the console. Not anywhere else. I already gave you an alternative way to write gotoxy(). Use the windows API or use escape sequences. Both will work.

Link to comment
Share on other sites

You wont need gotoxy while developing real life applications. Like i said gotoxy works only in the console. Not anywhere else. I already gave you an alternative way to write gotoxy(). Use the windows API or use escape sequences. Both will work.

but dude i didn't got how to apply it and requested a sample code for it..!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...