C Programming Tutorial

 

Reading User Values

The previous program is good, but it would be better if it read in the values 5 and 7 from keyboard that is typed by the user instead of using constants. This is the program:

#include <stdio.h>

int main()
{
    int d,e,f;
    printf("Enter the first value:");
    scanf("%d", &d);
    printf("Enter the second value:");
    scanf("%d", &e);
    f=d+e;
    printf("%d + %d = %d\n", d,e,f);
    getchar();
    getchar();
    return 0;
}

Just by using command ‘scanf’ the Processor immediately read typed character from the keyboard. The character typed will be stored in variable d and e. & is the address operator in C: It returns the address of the variable. You must use the & operator in scanf on any variable of type char, int, or float. If you leave out the & operator, there is no error when you compile the program but you will get an error when you run the program.

There error as shown above is 4 + 5 = 4206601. This is due to missing & operator for variable d.

c003

c004

Microcontroller

What is a Microcontroller?

Microcontroller Specification

Programming PIC16F877A

Playing with a C Programming and PIC16F877A

Creating a Digital Clock using PIC16F877A, LCD and DS1337 Clock IC from Dallas

How to Load Hex File into PIC16F877A

 

Articles :

Lightning Surge Testing

Bit Error Rate Testing

Insertion Loss Testing

 

Light Emitting Diode

DC Power Jack

Voltage Regulator and Diode

Transistor and Operational Amplifier

Trimmer Pot, Relay and PCB

 

Understanding PIC16F877A

Product Development Using PIC16F877A

More Product Development Using PIC16F877A

PIC16F877A Input Output Overview

Interfacing PIC16F877A With LCD

 

VoIP Basic

VoIP Phone

Using VoIP Through Normal PSTN Telephone

What is Codec?

 

C Programming Tutorial

Introduction

What is C programming language?

The First C Program

The First C Program - Explanation

Variables

Printf

Reading User Values

Scanf

Looping

Using FOR loop

Arrays

More on Arrays

Example Program that use Arrays to Compare 6 PIN number

If, Else If, Else

Functions

Pointers

Summary

 

 

 

 

 

 

 

 

 

 

 

Copyright www.electronics.netmyne.com.