Conversion of atoi, itoa and demonstration of clock() function

Conversion of atoi, itoa and demonstration of clock() function
In this article we will see the the conversion of integer to character using itoa() function
  conversion of character to integer using atoi() function
  and working of clock() function.

 
//The following program is designed to show you the working of storage
//classes and fucntions

#include <stdlib.h>
#include <stdio.h>
#include<time.h>
#include<dos.h>

void main()
{
   int n,number=79;
   char *str = "abc",string[25];
   clock_t start, end;
   clrscr();

   n = atoi(str); //it converts string to integer
   printf("string = %s integer = %d\n", str, n);

   itoa(number, string, 10);//it converts integer to a string
   printf("integer = %d string = %s\n", number, string);



   start = clock(); //Returns number of clock ticks since program start

   delay(1000);

   end = clock();
   printf("The time was: %f\n", (end - start) / CLK_TCK);

   //clock can be used to determine the time interval between two events.

   getch();
}
Output: We are considering integer and character values and doing the type casting from one to another, the output will be as follow,







Comments