-->

Facebook

Jasper Roberts - Blog

Thursday, September 18, 2014

scanf()

The ...scanf functions do the following:
- Scan a series of input fields one character at a time
- Format each field according to a corresponding format specifier passed in the format string *format.
- Store the formatted input at an address passed as an argument following format


from: turbo c

Void


  • void (type)

Empty data type

When used as a function return type, void means that the function does not return a value.

void hello(char *name)
  {
    printf("Hello, %s.",name);
  }


When found in a function heading, void means the function does not take any parameters.


  • int init(void)

  {
    return 1;
                   }


  • Void pointers:

Pointers can also be declared as void.

Void pointers can't be dereferenced without explicit casting. This is because the compiler can't determine the size of the object the pointer points to.

Example:
  int x;
float r;
  void *p = &x;          /* p points to x */

int main (void)
  {
    *(int *) p = 2;
    p = &r;              /* p points to r */
    *(float *)p = 1.1;
  }

from: turbo c

printf()

The ...printf functions do the following:
  - Accept a series of arguments
  - Apply to each argument a format specifier contained in the format string *format
  - Output the formatted data (to the screen, a stream, stdin, or a string)

These functions apply the first format specifier to the first argument, the second specifier to the second argument, the third to the third, etc., to the end of the format.

    syntax:
Printf("text");
         
    Example:
printf("Hello World!!");

    syntax:
printf("text datatype_specifier", variable name);
 
    Example:
printf("my roll number is : %d", rollnumber);

from: turbo c

getch()

getch reads a single character directly from the keyboard, without echoing to the screen.

example: getch();

from: turbo c

clrscr()

Clears text mode window

clrscr clears the current text window and places the cursor in the upper left-hand corner (at position 1,1).

example: clrscr();

from: turbo c

# (pound sign)

It indicates a preprocessor directive when it occurs as the first non-whitespace character on a line.

It signifies a compiler action, not necessarily associated with code generation.

# and ## (double pound signs) are also used as operators to perform token replacement and merging during the preprocessor scanning phase.

from: turbo c

Header file in C

Header file  - -  What It Does

 alloc.h      - -  Declares memory management functions (allocation,deallocation, etc.).
 assert.h     - -  Defines the assert debugging macro.
 bcd.h        - -  Declares the C++ class bcd and the overloaded operators for bcd and bcd math functions.
 bios.h       - -  Declares various functions used in calling IBM-PC ROM BIOS routines.
 complex.h    - -  Declares the C++ complex math functions.
 conio.h      - -  Declares various functions used in calling the DOS console I/O routines.
 ctype.h      - -  Contains information used by the character classification and character conversion macros.
 dir.h        - -  Contains structures, macros, and functions for working with directories and path names.
 direct.h     - -  Defines structures, macros, and functions for working with directories and path names.
 dirent.h     - -  Declares functions and structures for POSIX directory operations.
 dos.h        - -  Defines various constants and gives declarations needed for DOS and 8086-specific calls.
 errno.h      - -  Defines constant mnemonics for the error codes.
 fcntl.h      - -  Defines symbolic constants used in connection with the library routine open.
 float.h      - -  Contains parameters for floating-point routines.
 fstream.h    - -  Declares the C++ stream classes that support file input and output.
 generic.h    - -  Contains macros for generic class declarations.
 graphics.h   - -  Declares prototypes for the graphics functions.
 io.h         - -  Contains structures and declarations for low-level input/output routines.
 iomanip.h    - -  Declares the C++ streams I/O manipulators and contains macros for creating parameterized manipulators.
 iostream.h   - -  Declares the basic C++ (version 2.0) streams (I/O) routines.
 limits.h     - -  Contains environmental parameters, information about compile-time limitations, and ranges of integral quantities.
 locale.h     - -  Declares functions that provide country- and language-specific information.
 malloc.h     - -  Memory management functions and variables.
 math.h       - -  Declares prototypes for the math functions, defines the macro HUGE_VAL, and declares the exception structure used by matherr.
 mem.h        - -  Declares the memory-manipulation functions. (Many of these are also defined in string.h.)
 memory.h     - -  Memory manipulation functions.
 new.h        - -  Access to operator new and newhandler.
 process.h    - -  Contains structures and declarations for the spawn... and exec... functions.
 search.h     - -  Declares functions for searching and sorting.
 setjmp.h     - -  Defines a type used by longjmp and setjmp.
 share.h      - -  Defines parameters used in functions that use file-sharing.
 signal.h     - -  Defines constants and declarations for signal and raise.
 stdarg.h     - -  Defines macros used for reading the argument list in functions declared to accept a variable number of arguments.
 stddef.h     - -  Defines several common data types and macros.
 stdio.h      - -  Defines types and macros needed for the Standard I/O Package defined in Kernighan and Ritchie and extended under UNIX System V. Defines the standard I/O predefined streams stdin, stdout, stdprn, and stderr, and declares stream-level I/O routines.
 stdiostr.h   - -  Declares the C++ (version 2.0) stream classes for use with stdio FILE structures.
 stdlib.h     - -  Declares several commonly used routines: conversion routines, search/sort routines, and other miscellany.
 stream.h     - -  Declares the C++ (version 1.2) streams (I/O) routines.
 string.h     - -  Declares several string- and memory-manipulation routines.
 strstrea.h   - -  Declares the C++ stream classes for use with byte arrays in memory.
 sys\locking.h- -  Definitions for mode parameter of locking function.
 sys\stat.h   - -  Defines symbolic constants used for opening and creating files.
 sys\timeb.h  - -  Declares the function ftime and the structure timeb that ftime returns.
 sys\types.h  - -  Declares the type time_t used with time functions.
 time.h       - -  Defines a structure filled in by the time-conversion routines, and a type used by other time routines; also provides prototypes for these routines.
 utime.h      - -  Declares the functions utime and the structure utimbuf
 values.h     - -  Defines important constants, including machine dependencies; provided for UNIX System V compatibility.
 varargs.h    - - Defines old style marcos for processing variable argumnet lists.  Superceded by stdarg.h

#include (directive)

Treats text in the file specified by filename as if it appeared in the current file.

Syntax:
  #include "filename"
  #include <filename>

#include "filename" searches the source path first, then the include path.

#include <filename> does not search the source directory.

Examples:
  #include <stdio.h>
#include "main.h"

PRACTICAL-SET—1

Write a C Program to select & print the largest of the three nos. using Nested-If-Else statement.

#include<stdio.h>
#include<conio.h>

void main()
{
      int a,b,c;
      clrscr();

      printf("Enter the values of a: ");
      scanf("%d",&a);

      printf("Enter the values of b: ");
      scanf("%d",&b);

      printf("Enter the values of c: ");
      scanf("%d",&c);



     if(a>b)
    {
             if(a>c)
             {
                       printf(" a is largest number.");
             }
             else
            {
                        printf(" c is largest number.");
            }
     }
    
    else
    {
            if(b>c)
           {
                       printf(" b is largest number.");
           }
           else
          {
                      printf(" c is largest number.");
          }
    }

getch();

}



OUTPUT:

largest.c

Write a C Program to convert years into months and days.

#include<stdio.h>
#include<conio.h>

void main()
{
int years,months,days;
clrscr();

printf("\n Enter the number of years: ");
scanf("%d",&years);

months = 12 * years;

days = 365 * years;

printf("\n Total Months are : %d",months);
printf("\n Total Days are : %d",days);

getch();

}

OUTPUT:

c program to convert years into months and days
years.c

Write a C Program that reads two nos. from key board and gives their addition, subtraction, multiplication, division and modulo.

#include<stdio.h>
#include<conio.h>

void main()
{
int value1, value2, addition, subtraction, multiply;
float divide,mod;

clrscr();

printf("\n Enter the value1: ");
scanf("%d",&value1);

printf("\n Enter the value2: ");
scanf("%d",&value2);

addition = value1 + value2;
subtraction = value1 - value2;
multiply = value1 * value2;
divide = value1 / (float)value2;
mod = value1 % value2;

printf("\n Addition       = %d + %d = %d",value1,value2,addition);
printf("\n Subtraction    = %d - %d = %d",value1,value2,subtraction);
printf("\n Multiplication = %d * %d = %d",value1,value2,multiply);
printf("\n Division       = %d / %d = %.0f",value1,value2,divide);
printf("\n Modulo         = %d MOD %d = %.0f",value1,value2,mod);
 
    getch();
}

OUTPUT:

c program to add, sub, multi, div of two numbers
calculator.c


RELATED PROGRAMS

a. Writea program to print ―HELLO FRIENDS!!
c. Writea program to convert years intomonths and days. 
d. Write a prograto solve Quadratic Equation.