• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer

Power Inception

Resources for All Things Power Related

  • Home
  • Tech News
  • Product Reviews
  • Refrigerators
  • DC Circuits
  • Networking
  • Physics
  • Apps
  • Business
How to write C programs

How to write C programs

02/25/2010 By PowerInception.com

To write c program you have to need a compiler such as borland, Turbo C etc. In this post I will discuss about what view of C programs mainly basic c program. How can we write? How C programs look? How to write c program?

We will see some examples to learn it. The main aim of this post is to explain basic idea of C programming.

This is c programming structure.

Yes. This is C program, if we write this line the compiler will not show error. Because there is no error. This is the main structure of C programming language. It is called main function of programming C and entry point of program. Originally a C program is the summation of one or many functions. But main function must have in programming C and other function must be written within the second bracket “{ }”. This is the rule of C. We can write above program as below also

Important sight is that every letters should be written on small letter. Because there is huge difference between small and capital letter in C language. So, C is known as case sensitive language. We will not write main to Main or MAIN or mAin, the compiler will show error. Now let we will write a program which output screen will

I am a new programmer.

For this work we have to use c print function

printf (“I am a new programmer”);

To show any statement we have to write the statement with double quotation (“ ”) within printf( ) function’s first bracket ‘( )’. C compiler can not work without main( ). So, we should write printf( ) function within main( ) function’s second bracket ‘{ }’.

If we type above program, may be we will get three error at the time of compiling.

Example

Compiling     NONAMEOO.CPP:

Error             NONAMEOO.CPP 3: Function ‘printf’ should have a prototype

Error             NONAMEOO.CPP 4: Statement missing;

Error             NONAMEOO.CPP 4: compound statement missing

C programming basics

(i) Cause of first error is

Using a function in C declaration of prototype is needed for that function. Printf ( ) is a library function and its prototype is written in a file named stdio.h. So, it is needed to write the name of stdio.h before and before main( ). It is the rule of C also. These types of files are called header file. The rule of writing header file is

 

structure of c programming

 

(i) The cause of second error is missing semicolon (;). We must use semicolon at the end of instruction. Using semicolon in an instruction is called statement.(ii) Third error is the resultant error of first two errors. Now, if we write the program as below, compiler will not show any error.

 

basic of c programming

 

If we run c programs we will see “I am a new programmer” on the output screen. But to see output you have to press Alt+F5 must. Look at given program below,

 

c programming introduction

 

 

Two library functions named clrscr ( ) and getch ( ) are used in this program. And header file of these functions is conio.h. If you want to know the act of the two functions, just write the program and run. You will find easily yourself. There are many library functions for different sections. As a new learner you may desire to learn about library functions. You can learn about library function from the help of expert programmer or reading book.

There is a help option in TC editor you can learn from it also about library function pressing Ctrl+F1. Every instruction should be written within main ( ) function and every instruction should be ended by semicolon (;). Semicolon means the separation of instruction. So, we can write many instructions or statements besides using semicolon, compiler without find any error.

Example:

 

programming C basic structure

 

But writing separately is easier to understand. One important thing is if any function many statements, first statement will work first then seemed and it will finished until getting second bracket ‘}’ So, statements are written one by one below serially for working serially. To get clear concept see the program below

 

programmin c basics

 

Run the program pressing Ctrl+F9. You will find the output

 

c basic program

How to run c programs

What do we do to send writing to anyone? We use paper. Here paper is medium. Similarly in programming C language we need to write programs where the compiler can read the programs and realize it. So, an editor program is remained with every compiler, which works as paper. And the pen of this paper is keyboard.

Like other compiler Turbo C has an editor. We can give changing/editing/save command using c program editor.
We will write program on text editor in Turbo C. First start Turbo C; you will see a screen as below.

how to run c programs

This is the IDE of Turbo C.
Now click File>New. Then a blue screen will be appeared as below image. Primarily the name of the window of Turbo C will be NONAMEOO.CPP.

how c program run

We will type our program on the above window. Suppose we have written the program below on the window. This is small c program.

how does c program runs

They are called source code also. I know that at a first glance learner will not understand the given program. But don’t worry I will discuss all about of C programming. If you read all the post of programming C in this blog, I believe you will have the ability of writing program.

However, write the program on the blue screen. Then click compile and compile the program. If error you have to correct it. There is no error in the program which I have written. Before running a program you have to save it by clicking File>Save. You can save the name of the program as you desire. Finally run the program. You will get an output as the image given below running c program

c program result

This is the output of a program. We can run and save a program in this way.

How does C printf runs on programming C

Printf  in  C:

This is an easy printf tutorial.

C language printf function is used to show output of program. C programming printf is the function which shows the output result of program on screen. Using printf we can show any statement on screen, the statement must be written in the bracket of printf( ) function with double quotation. It is written as string.

For example, now I am writing a program where user will see the statement

“I am an engineer.”

 

The sentence which is written in the bracket of printf( ) is called parameter or argument. Now look the program below

 

Everyone may think that the printf output will be
“I am an engineer.
This is engineers blogsite.”

It means the output of this program will two lines. But it is not true. The output of this programme will be only one line as

“I am an engineer this is engineers blogsite.”

Because printf( ) function shows output from the beginning of monitor screen and compiler starts showing next output on there where first output has finished.

But sometimes we need to show output by many lines. In this situation backslash character or escape sequence character, “n” is used. Using “n” compiler shows next output below next line from first output. If we rewrite the program as below

Here we have used “n” in first printf( ), so compiler has gone next line showing first output. Next output has shown as a new line below first output. “n” works as ENTER of keyboard. So, the output of above program will be shown by two separate lines.

Important matter is that we will not see “n” on the output screen. Because these types of backslash character (n, a, r etc) are used for a specific reason. The compiler knows the reason, it knows which character is used for which purpose. So, compiler does the work we need.

 

Filed Under: Programming C Tagged With: C, write C programs

Primary Sidebar

best Power Probe 3 Master Kit

Best Power Probe Master Kit Reviews And Buying Guide

Are you confused to select Power Probe 3 Master Kit or Power Probe 4 Master Kit? Which one is perfect for your car short-open circuit test, ground feed, fuel injection test, audio test. ​Power probe 3 master kit is most popular and power probe 4 master kit has the latest technology. Which one you need? […]

The Complete Guide to Purchasing Two-Way Radios for Businesses

5 Key Benefits of a GPS Asset Tracker

Document Security Mistakes

4 Common Document Security Mistakes to Avoid for Your Business

Well Drilling Contractor

5 Tips for Hiring a Well Drilling Contractor

Emerging Trends in Business

How to Keep up With Emerging Trends in Business

3D Printing Services

How to Pick 3D Printing Services: The Complete Guide for Businesses

Product Reviews for Small Businesses

6 Tips on Managing Product Reviews for Small Businesses

Buy Chemicals Online

Can You Buy Chemicals Online? Legality and Considerations

Best ups for gaming computer

10 Best UPS For Gaming PC For Ultimate Backup Power

Best Circuit Breaker Panels

Proven 10 Best Circuit Breaker Panel For Ultimate Protection

best ohm meter review

14 Best Ohm Meter To Buy Review And Buyer’s Guide

Footer

About us

PowerInception.com provides thorough tech reviews and the latest technology news. I participate in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com. As an Amazon Associate I earn from qualifying purchases.

Privacy policy

Affiliate Disclosure

Contact us

Popular posts

3D Printing Services

How to Pick 3D Printing Services: The Complete Guide for Businesses

Product Reviews for Small Businesses

6 Tips on Managing Product Reviews for Small Businesses

Buy Chemicals Online

Can You Buy Chemicals Online? Legality and Considerations

Best ups for gaming computer

10 Best UPS For Gaming PC For Ultimate Backup Power

best Power Probe 3 Master Kit

Best Power Probe Master Kit Reviews And Buying Guide

Categories

  • AC Circuits (1)
  • Apps (16)
  • Battery (4)
  • Business (77)
  • DC Circuits (19)
  • Digital electronics (13)
  • Economics (2)
  • Electrical & Electronics (20)
  • Featured (15)
  • Financial Tech (6)
  • Generator (7)
  • Networking (16)
  • Payroll and HR (4)
  • Physics (30)
  • Product Review (30)
  • Programming C (2)
  • Refrigerators (4)
  • Renewable Energy Technology (3)
  • Software (25)
  • Tech News and Reviews (84)
  • Transformers (6)
  • Websites and Internet (19)

Copyright © 2023 Power Inception