Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: How do I write code to find an amount of free disk space available on current drive?

Answer: Use getdfree( ) function as shown in follow code.

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

main( )
{
int dr ; struct dfree disk ;
long freesp ;

dr = getdisk( ) ;
getdfree ( dr + 1 , &disk ) ;

if ( disk.df_sclus == 0xFFFF )
{
printf ( "ngetdfree( ) function failedn");
exit ( 1 ) ;
}

freesp = ( long ) disk.df_avail
* ( long ) disk.df_bsec
* ( long ) disk.df_sclus ;
printf ( "nThe current drive %c: has %ld bytes
available as free spacen", 'A' + dr, freesp ) ;
}

17.

Use of array indices...
If we wish to store a character in a char variable ch and the character to be stored depends on the value of another variable say color (of type int), then the code would be as shown below:

switch ( color )
{
case 0 :
ch = 'R' ;
break ;
case 1 :
ch = 'G' ;
break ;
case 2 :
ch = 'B' ;
break ;
}
In place of switch-case we can make use of the value in color as an index for a character array. How to do this is shown in following code snippet.

char *str = "RGB' ;
char ch ;
int color ;
// code
ch = str[ color ] ;
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook