Pages

Showing posts with label ct. Show all posts
Showing posts with label ct. Show all posts

Saturday, 5 July 2014

C – Dynamic memory allocation

Dynamic memory allocation in C:

     The process of allocating memory during program execution is called dynamic memory allocation.

Dynamic memory allocation functions in C:

C language offers 4 dynamic memory allocation functions. They are,
  1. malloc()
  2. calloc()
  3. realloc()
  4. free()
S.no
Function
Syntax
1 malloc () malloc (number *sizeof(int));
2 calloc () calloc (number, sizeof(int));
3 realloc () realloc (pointer_name, number * sizeof(int));
4 free () free (pointer_name);

1. malloc() function in C:

  • malloc () function is used to allocate space in memory during the execution of the program.
  • malloc () does not initialize the memory allocated during execution.  It carries garbage value.
  • malloc () function returns null pointer if it couldn’t able to allocate requested amount of memory.

Example program for malloc() function in C:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
     char *mem_allocation;
     /* memory is allocated dynamically */
     mem_allocation = malloc( 20 * sizeof(char) );
     if( mem_allocation== NULL )
     {
        printf("Couldn't able to allocate requested memory\n");
     }
     else
     {
        strcpy( mem_allocation,"fresh2refresh.com");
     }
     printf("Dynamically allocated memory content : " \
            "%s\n", mem_allocation );
     free(mem_allocation);
}

Output:

Dynamically allocated memory content : computer science

2. calloc() function in C:

  • calloc () function is also like malloc () function. But calloc () initializes the allocated memory to zero. But, malloc() doesn’t.

Example program for calloc() function in C:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
     char *mem_allocation;
     /* memory is allocated dynamically */
     mem_allocation = calloc( 20, sizeof(char) );
     if( mem_allocation== NULL )
     {
        printf("Couldn't able to allocate requested memory\n");
     }
     else
     {
         strcpy( mem_allocation,"computer science");
     }
         printf("Dynamically allocated memory content   : " \
                "%s\n", mem_allocation );
         free(mem_allocation);
}

Output:

Dynamically allocated memory content : computer science

3. realloc() function in C:

  • realloc () function modifies the allocated memory size by malloc () and calloc () functions to new size.
  • If enough space doesn’t exist in memory of current block to extend, new block is allocated for the full size of reallocation, then copies the existing data to new block and then frees the old block.

 4. free() function in C:

  • free () function frees the allocated memory by malloc (), calloc (), realloc () functions and returns the memory to the system.

Example program for realloc() and free() functions in C:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char *mem_allocation;
    /* memory is allocated dynamically */
    mem_allocation = malloc( 20 * sizeof(char) );
    if( mem_allocation == NULL )
    {
        printf("Couldn't able to allocate requested memory\n");
    }
    else
    {
       strcpy( mem_allocation,"computerscience");
    }
    printf("Dynamically allocated memory content  : " \
           "%s\n", mem_allocation );
    mem_allocation=realloc(mem_allocation,100*sizeof(char));
    if( mem_allocation == NULL )
    {
        printf("Couldn't able to allocate requested memory\n");
    }
    else
    {
        strcpy( mem_allocation,"space is extended upto " \
                               "100 characters");
    }
    printf("Resized memory : %s\n", mem_allocation );
    free(mem_allocation);
}

Output:

Dynamically allocated memory content : computerscience
Resized memory : space is extended upto 100 characters

Difference between static memory allocation and dynamic memory allocation in C:

S.no Static memory allocation Dynamic memory allocation
1 In static memory allocation, memory is allocated while writing the C program. Actually, user requested memory will be allocated at compile time. In dynamic memory allocation, memory is allocated while executing the program. That means at run time.
2 Memory size can’t be modified while execution. 
Example: array
Memory size can be modified while execution. 
Example: Linked list

Difference between malloc() and calloc() functions in C:


S.no malloc() calloc()
1 It allocates only single block of requested memory It allocates multiple blocks of requested memory
2 int *ptr;ptr = malloc( 20 * sizeof(int) );For the above, 20*4 bytes of memory only allocated in one block. 
Total = 80 bytes
int *ptr;Ptr = calloc( 20, 20 * sizeof(int) );For the above, 20 blocks of memory will be created and each contains 20*4 bytes of memory. 
Total = 1600 bytes
3 malloc () doesn’t initializes the allocated memory. It contains garbage values calloc () initializes the allocated memory to zero
4 type cast must be done since this function returns void pointer int *ptr;ptr = (int*)malloc(sizeof(int)*20 ); Same as malloc () function int *ptr;ptr = (int*)calloc( 20, 20 * sizeof(int) );

C – Summary of C functions

As you know, C functions are basic building blocks in every C program. We have given key points those to be kept in mind for using existing C library functions and writing our own functions in a C program efficiently.

Key points to remember while writing functions in C:

  • All C programs contain main() function which is mandatory.
  • main() function is the function from where every C program is started to execute.
  • Name of the function is unique in a C program.
  • C Functions can be invoked from anywhere within a C program.
  • There can any number of functions be created in a program. There is no limit on this.
  • There is no limit in calling C functions in a program.
  • All functions are called in sequence manner specified in main() function.
  • One function can be called within another function.
  • C functions can be called with or without arguments/parameters. These arguments are nothing but inputs to the functions.
  • C functions may or may not return values to calling functions. These values are nothing but output of the functions.
  • When a function completes its task, program control is returned to the function from where it is called.
  • There can be functions within functions.
  • Before calling and defining a function, we have to declare function prototype in order to inform the compiler about the function name, function parameters and return value type.

  • C function can return only one value to the calling function.
  • When return data type of a function is “void”, then, it won’t return any values
  • When return data type of a function is other than void such as “int, float, double”, it returns value to the calling function.
  • main() program comes to an end when there is no functions or commands to execute.
  • There are 2 types of functions in C. They are, 1. Library functions 2. User defined functions

C – Variable length argument

  • Variable length arguments is an advanced concept in C language offered by c99 standard. In c89 standard, fixed arguments only can be passed to the functions.
  • When a function gets number of arguments that changes at run time, we can go for variable length arguments.
  • It is denoted as … (3 dots)
  • stdarg.h header file should be included to make use of variable length argument functions.

Example program for variable length arguments in C:

#include <stdio.h>
#include <stdarg.h>

int add(int num,...);

int main()
{
     printf("The value from first function call = " \
            "%d\n", add(2,2,3));
     printf("The value from second function call= " \
            "%d \n", add(4,2,3,4,5));

     /*Note - In function add(2,2,3), 
                   first 2 is total number of arguments
                   2,3 are variable length arguments
              In function add(4,2,3,4,5), 
                   4 is total number of arguments
                   2,3,4,5 are variable length arguments
     */

     return 0;
}

int add(int num,...)
{
     va_list valist;
     int sum = 0;
     int i;

     va_start(valist, num);
     for (i = 0; i < num; i++)
     {
         sum += va_arg(valist, int);
     }
     va_end(valist);
     return sum;
}

Output:

The value from first function call = 5
The value from second function call= 14

       In the above program, function “add” is called twice. But, number of arguments passed to the function gets varies for each. So, 3 dots (…) are mentioned for function ‘add” that indicates that this function will get any number of arguments at run time.

C – Command line arguments

Command line arguments in C:

      main() function of a C program accepts arguments from command line or from other shell scripts by following commands. They are,
  • argc
  • argv[]
where,
argc      - Number of arguments in the command line including program name
argv[]   – This is carrying all the arguments
  • In real time application, it will happen to pass arguments to the main program itself.  These arguments are passed to the main () function while executing binary file from command line.
  • For example, when we compile a program (test.c), we get executable file in the name “test”.
  • Now, we run the executable “test” along with 4 arguments in command line like below.
./test this is a program
Where,
argc             =       5
argv[0]         =       “test”
argv[1]         =       “this”
argv[2]         =       “is”
argv[3]         =       “a”
argv[4]         =       “program”
argv[5]         =       NULL

Example program for argc() and argv() functions in C:

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

int main(int argc, char *argv[])   //  command line arguments
{
if(argc!=5) 
{
   printf("Arguments passed through command line " \
          "not equal to 5");
   return 1;
}

   printf("\n Program name  : %s \n", argv[0]);
   printf("1st arg  : %s \n", argv[1]);
   printf("2nd arg  : %s \n", argv[2]);
   printf("3rd arg  : %s \n", argv[3]);
   printf("4th arg  : %s \n", argv[4]);
   printf("5th arg  : %s \n", argv[5]);

return 0;
}

 Output:


Program name : test
1st arg : this
2nd arg : is
3rd arg : a
4th arg : program
5th arg : (null)

C – trunc() function

  • trunc( ) function in C truncates the decimal value from floating point value and returns integer value.
  • ”math.h” header file supports trunc( ) function in C language. Syntax for trunc( ) function in C is given below.
double trunc (double a);
float truncf (float a);
long double truncl (long double a);

Example program for trunc( ) function in C:

#include <stdio.h>      
#include <math.h>      

int main()
{
   printf ("truncated value of 16.99 = %f\n", trunc (16.99) );
   printf ("truncated value of 20.1  = %f\n", trunc (20.1) );
   return 0;
}

Output:


truncated value of 16.99 = 16.000000
truncated value of 20.1 = 20.000000

C – pow() function

  • pow( ) function in C is used to find the power of the given number.
  • ”math.h” header file supports pow( ) function in C language. Syntax for pow( ) function in C is given below.
double pow (double base, double exponent);

Example program for pow() function in C:

#include <stdio.h>      
#include <math.h>      

int main()
{
   printf ("2 power 4 = %f\n", pow (2.0, 4.0) );
   printf ("5 power 3 = %f\n", pow (5, 3) );
   return 0;
}

Output:


2 power 4 = 16.000000
5 power 3 = 125.000000

C – sqrt() function

  • sqrt( ) function in C is used to find the square root of the given number.
  • ”math.h” header file supports sqrt( ) function in C language. Syntax for sqrt( ) function in C is given below.
double sqrt (double x);

Example program for sqrt() function in C:

#include <stdio.h>      
#include <math.h>      

int main()
{
   printf ("sqrt of 16 = %f\n", sqrt (16) );
   printf ("sqrt of  2 = %f\n", sqrt (2) );
   return 0;
}

Output:


sqrt of 16 = 4.000000
sqrt of 2 = 1.414214

C – sin() cos() tan() exp() log() function

  • sin( ), cos( ) and tan( ) functions in C are used to calculate sine, cosine and  tangent values.
  • sinh( ), cosh( ) and tanh( ) functions are used to calculate hyperbolic sine, cosine and tangent values.
  • exp( ) function is used to calculate the exponential “e” to the xth power. log( ) function is used to calculates natural logarithm and log10( ) function is used to calculates base 10 logarithm.
  • ”math.h” header file supports all these functions in C language.

Example program for sin(), cos(), tan(), exp() and log()  in C:

#include <stdio.h>

#include <math.h>

int main()

{
       float i = 0.314;
       float j = 0.25;
       float k = 6.25;
       float sin_value = sin(i);
       float cos_value = cos(i);
       float tan_value = tan(i);
       float sinh_value = sinh(j);
       float cosh_value = cosh(j);
       float tanh_value = tanh(j);
       float log_value = log(k);
       float log10_value = log10(k);
       float exp_value = exp(k);

       printf("The value of sin(%f) : %f \n", i, sin_value);
       printf("The value of cos(%f) : %f \n", i, cos_value);
       printf("The value of tan(%f) : %f \n", i, tan_value);
       printf("The value of sinh(%f) : %f \n", j, sinh_value);
       printf("The value of cosh(%f) : %f \n", j, cosh_value);
       printf("The value of tanh(%f) : %f \n", j, tanh_value);
       printf("The value of log(%f) : %f \n", k, log_value);
       printf("The value of log10(%f) : %f \n",k,log10_value);
       printf("The value of exp(%f) : %f \n",k, exp_value);
       return 0;
}

Output:


The value of sin(0.314000) : 0.308866
The value of cos(0.314000) : 0.951106
The value of tan(0.314000) : 0.324744
The value of sinh(0.250000) : 0.252612
The value of cosh(0.250000) : 1.031413
The value of tanh(0.250000) : 0.244919
The value of log(6.250000) : 1.832582
The value of log10(6.250000) : 0.795880
The value of exp(6.250000) : 518.012817

C – ceil() function

  • ceil( ) function in C returns nearest integer value which is greater than or equal to the argument passed to this function.
  • ”math.h” header file supports ceil( ) function in C language. Syntax for ceil( ) function in C is given below.
double ceil (double x);

Example program for ceil() function in C:

 #include <stdio.h>
#include <math.h>
 int main()
{
       float i=5.4, j=5.6;
       printf("ceil of  %f is  %f\n", i, ceil(i));
       printf("ceil of  %f is  %f\n", j, ceil(j));
       return 0;
}

Output:


ceil of 5.400000 is 6.000000
ceil of 5.600000 is 6.000000

C – round() function

  • round( ) function in C returns the nearest integer value of the float/double/long double argument passed to this function.
  • If decimal value is from ”.1 to .5″, it returns integer value less than the argument. If decimal value is from “.6 to .9″, it returns the integer value greater than the argument.
  • ”math.h” header file supports round( ) function in C language. Syntax for round( ) function in C is given below.
double round (double a);
float roundf (float a);
long double roundl (long double a);

Example program for round() function in C:

 #include <stdio.h>
#include <math.h>
 int main()
{
       float i=5.4, j=5.6;
       printf("round of  %f is  %f\n", i, round(i));
       printf("round of  %f is  %f\n", j, round(j));
       return 0;
}

Output:


round of 5.400000 is 5.000000
round of 5.600000 is 6.000000

C – floor() function

  • floor( ) function in C returns the nearest integer value which is less than or equal to the floating point argument passed to this function.
  • ”math.h” header file supports floor( ) function in C language. Syntax for floor( ) function in C is given below.
double floor ( double x );

Example program for floor( ) function in C:

 #include <stdio.h>
#include <math.h>
 int main()
{
       float i=5.1, j=5.9, k=-5.4, l=-6.9;
       printf("floor of  %f is  %f\n", i, floor(i));
       printf("floor of  %f is  %f\n", j, floor(j));
       printf("floor of  %f is  %f\n", k, floor(k));
       printf("floor of  %f is  %f\n", l, floor(l));
       return 0;
}

Output:

floor of 5.100000 is 5.000000
floor of 5.900000 is 5.000000
floor of -5.400000 is -6.000000
floor of -6.900000 is -7.000000

C – abs() function

  • abs( ) function in C returns the absolute value of an integer. The absolute value of a number is always positive. Only integer values are supported in C.
  • “stdlib.h” header file supports abs( ) function in C language. Syntax for abs( ) function in C is given below.
int abs ( int n );

Example program for abs( ) function in C:

#include <stdio.h>
#include <stdlib.h>
int main()
{
   int m = abs(200);     // m is assigned to 200
   int n = abs(-400);    // n is assigned to -400

   printf("Absolute value of m = %d\n", m);
   printf("Absolute value of n = %d \n",n);
   return 0;
}

Output:

Absolute value of m = 200
Absolute value of n = 400


    Other inbuilt arithmetic functions in C:

    Friday, 4 July 2014

    C – All other library functions

    All C inbuilt functions which are declared in all other header files such as stdarg.h, signal.h, setjmp.h, locale.h, errno.h and assert.h are given below.
    ……

    List of all other inbuilt functions in C:


    S.no
    Header_file
    Function
    Description
    1 stdarg.h va_start() This function indicates the start process of variable length argument list in a program
    va_arg() This function is used to fetch the arguments from variable length argument list
    va_end() This function indicates the end process of variable length argument list in a program
    2 signal.h signal() It is used to install signal handler
    raise() It is used to raise signal in a C program
    3 setjmp.h setjmp() This function prepares to use longjmp() function
    longjmp() It is used for non local jump
    4 locale.h setlocale() It sets locale()
    localeconv() It gets locale conventions
    5 errno.h errno() This function sets errno value to 0 at the beginning of the program. This value is modified to other than 0 when an error occurs while any function call.
    6 assert.h assert() This function gets an integer as paramenter. If this paramenter is 0, writes message
    to stderr. Then, terminates the program. If this paramenter is non 0, it does nothing.

    C – ctype.h library functions

     All C inbuilt functions which are declared in ctype.h header file are given below. The source code for ctype.h header file is also given below for your reference.

    List of inbuilt C functions in ctype.h file:

    • “ctype.h” header file support all the below functions in C language. Click on each function name below for detail description and example programs.

    S.no Function Description
    1 isalpha() checks whether character is alphabetic
    2 isdigit() checks whether character is digit
    3 isalnum() checks whether character is alphanumeric
    4 isspace() checks whether character is space
    5 islower() checks whether character is lower case
    6 isupper() checks whether character is upper case
    7 isxdigit() checks whether character is hexadecimal
    8 iscntrl() checks whether character is a control character
    9 isprint() checks whether character is a printable character
    10 ispunct() checks whether character is a punctuation
    11 isgraph() checks whether character is a graphical character
    12 tolower() checks whether character is alphabetic & converts to lower case
    13 toupper() checks whether character is alphabetic & converts to upper case

    C – time.h library functions

    All C inbuilt functions which are declared in time.h header file are given below. The source code for time.h header file is also given below for your reference.

    List of inbuilt C functions in time.h file:


    S.no Functions Description
    1 setdate() This function used to modify the system date
    2 getdate() This function is used to get the CPU time
    3 clock() This function is used to get current system time
    4 time() This function is used to get current system time as structure
    5 difftime() This function is used to get the difference between two given times
    6 strftime() This function is used to modify the actual time format
    7 mktime() This function interprets tm structure as calendar time
    8 localtime() This function shares the tm structure that contains date and time informations
    9 gmtime() This function shares the tm structure that contains date and time informations
    10 ctime() This function is used to return string that contains date and time informations
    11 asctime() Tm structure contents are interpreted by this function as calendar time. This time is converted into string.

    C – math.h library functions

    All C inbuilt functions which are declared in math.h header file are given below. The source code for math.h header file is also given below for your reference.

    List of inbuilt C functions in math.h file:

    • “math.h” header file supports all the mathematical related functions in C language. All the arithmetic functions used in C language are given below.
    • Click on each function name below for detail description and example programs.

    S.no
    Function
    Description
    1 abs ( ) This function returns the absolute value of an integer. The absolute value of a number is always positive. Only integer values are supported in C.
    2 floor ( ) This function returns the nearest integer which is less than or equal to the argument passed to this function.
    3 round ( ) This function returns the nearest integer value of the float/double/long double argument passed to this function. If decimal value is from ”.1 to .5″, it returns integer value less than the argument. If decimal value is from “.6 to .9″, it returns the integer value greater than the argument.
    4 ceil ( ) This function returns nearest integer value which is greater than or equal to the argument passed to this function.
    5 sin ( ) This function is used to calculate sine value.
    6 cos ( ) This function is used to calculate cosine.
    7 cosh ( ) This function is used to calculate hyperbolic cosine.
    8 exp ( ) This function is used to calculate the exponential “e” to the xth power.
    9 tan ( ) This function is used to calculate tangent.
    10 tanh ( ) This function is used to calculate hyperbolic tangent.
    11 sinh ( ) This function is used to calculate hyperbolic sine.
    12 log ( ) This function is used to calculates natural logarithm.
    13 log10.(.) This function is used to calculates base 10 logarithm.
    14 sqrt ( ) This function is used to find square root of the argument passed to this function.
    15 pow ( ) This is used to find the power of the given number.
    16 trunc.(.) This function truncates the decimal value from floating point value and returns integer value.

    C – stdlib.h library functions

    All C inbuilt functions which are declared in stdlib.h header file are given below. The source code for stdlib.h header file is also given below for your reference.

    List of inbuilt C functions in stdlib.h file:


    S.no
    Function
    Description
    1 malloc() This function is used to allocate space in memory during the execution of the
    program.
    2 calloc() This function is also like malloc () function. But calloc () initializes the allocated
    memory to zero. But, malloc() doesn’t
    3 realloc() This function modifies the allocated memory size by malloc () and calloc ()
    functions to new size
    4 free() This function frees the allocated memory by malloc (), calloc (), realloc () functions
    and returns the memory to the system.
    5 abs() This function returns the absolute value of an integer . The absolute value of a
    number is always positive. Only integer values are supported in C.
    6 div() This function performs division operation
    7 abort() It terminates the C program
    8 exit() This function terminates the program and does not return any value
    9 system() This function is used to execute commands outside the C program.
    10 atoi() Converts string to int
    11 atol() Converts string to long
    12 atof() Converts string to float
    13 strtod() Converts string to double
    14 strtol() Converts string to long
    15 getenv() This function gets the current value of the environment variable
    16 setenv() This function sets the value for environment variable
    17 putenv() This function modifies the value for environment variable
    18 perror() This function displays most recent error that happened during library function call.
    19 rand() This function returns the random integer numbers
    20 delay() This function Suspends the execution of the program for particular time

    C – string.h library functions

    All C inbuilt functions which are declared in string.h header file are given below. The source code for string.h header file is also given below for your reference.

    List of inbuilt C functions in string.h file:


    S.no
    string functions
    Description
    1 strcat(str1, str2)  Concatenates str2 at the end of str1.
    2 strcpy(str1, str2)  Copies str2 into str1
    3 strlen(strl)  gives the length of str1.
    4 strcmp(str1, str2)  Returns 0 if str1 is same as str2. Returns <0 if strl < str2. Returns >0 if str1 > str2.
    5 strchr(str1,char)  Returns pointer to first occurrence of char in str1.
    6 strstr(str1, str2)  Returns pointer to first occurrence of str2 in str1.
    7 strcmpi(str1,str2)  Same as strcmp() function. But, this function negotiates case.  “A” and “a” are treated as same.
    8 strdup()  duplicates the string
    9 strlwr()  converts string to lowercase
    10 strncat()  appends a portion of string to another
    11 strncpy()  copies given number of characters of one string to another
    12 strrchr()  last occurrence of given character in a string is found
    13 strrev()  reverses the given string
    14 strset()  sets all character in a string to given character
    15 strupr()  converts string to uppercase
    16 strtok()  tokenizing given string using delimiter
    17 memset() It is used to initialize a specified number of bytes to null or any other value in the buffer
    18 memcpy() It is used to copy a specified number of bytes from one memory to another
    19 memmove() It is used to copy a specified number of bytes from one memory to another or to overlap on same memory.
    20 memcmp() It is used to compare specified number of characters from two buffers
    21 memicmp() It is used to compare specified number of characters from two buffers  regardless of the case of the characters
    22 memchr() It is used to locate the first occurrence of the character in the specified string

    C – conio.h library functions

    ll C inbuilt functions which are declared in conio.h header file are given below. The source code for conio.h header file is also given below for your reference.

    List of inbuilt C functions in conio.h file:


    S.no
    Function
    Description
    1 clrscr() This function is used to clear the output screen.
    2 getch() It reads character from keyboard
    3 getche() It reads character from keyboard and echoes to o/p screen
    4 textcolor() This function is used to change the text color
    5 textbackground() This function is used to change text background

    C – stdio.h library functions

    All C inbuilt functions which are declared in stdio.h header file are given below. The source code for stdio.h header file is also given below for your reference.

    List of inbuilt C functions in stdio.h file:


    S.no
    Function
    Description
    1 printf() This function is used to print the character, string, float, integer, octal and hexadecimal values onto the output screen
    2 scanf() This function is used to read a character, string, numeric data from keyboard.
    3 getc() It reads character from file
    4 gets() It reads line from keyboard
    5 getchar() It reads character from keyboard
    6 puts() It writes line to o/p screen
    7 putchar() It writes a character to screen
    8 clearerr() This function clears the error indicators
    9 f open() All file handling functions are defined in stdio.h header file
    10 f close() closes an opened file
    11 getw() reads an integer from file
    12 putw() writes an integer to file
    13 f getc() reads a character from file
    14 putc() writes a character to file
    15 f putc() writes a character to file
    16 f gets() reads string from a file, one line at a time
    17 f puts() writes string to a file
    18 f eof() finds end of file
    19 f getchar reads a character from keyboard
    20 f getc() reads a character from file
    21 f printf() writes formatted data to a file
    22 f scanf() reads formatted data from a file
    23 f getchar reads a character from keyboard
    24 f putchar writes a character from keyboard
    25 f seek() moves file pointer position to given location
    26 SEEK_SET moves file pointer position to the beginning of the file
    27 SEEK_CUR moves file pointer position to given location
    28 SEEK_END moves file pointer position to the end of file.
    29 f tell() gives current position of file pointer
    30 rewind() moves file pointer position to the beginning of the file
    31 putc() writes a character to file
    32 sprint() writes formatted output to string
    33 sscanf() Reads formatted input from a string
    34 remove() deletes a file
    35 fflush() flushes a file