is the floppy disk ready

March 31, 2009 by admin  
Filed under C

#include
#include

void main(void)
{
char buffer[8192];

// Try reading head 1, track 1, sector 1
if (biosdisk(2, 0, 1, 1, 1, 1, buffer))
printf(”Error accessing driven”);
else
printf(”Drive readyn”);
}

get the size of a file

March 30, 2009 by admin  
Filed under C

#include
#include
#include
#include

int main()
{
int fp;

long file_size;

if ((fp = open(”f:/cprojects/urls.txt”, O_RDONLY)) == -1)
printf(”Error opening the file n”);
else
{
file_size = filelength(file_handle);
printf(”The file size in bytes is %ldn”, file_size);
close(fp);
}
return 0;
}

file attributes

March 28, 2009 by admin  
Filed under C

#include
#include

int main()
{
int mode;
/*check a files attributes*/
mode = access(”f:/cprojects/urls.txt”,0);
if(mode)
printf(”File does not exist.n”);
else
/*check if the file can be written to*/
mode = access(”f:/cprojects/urls.txt”,2);
if(mode)
printf(”File cannot be written.n”);
else
printf(”file can be written to.n”);

/*check if file can be read*/
mode = access(”f:/cprojects/urls.txt”,4);
if(mode)
printf(”File cannot be read.n”);
else
printf(”File can be read.n”);

/*check if afile can be read/written*/
mode = access(”f:/cprojects/urls.txt”,6);
if(mode)
printf(”File cannot be read/written to.n”);
else
printf(”File can be read/written to.n”);

return 0;
}

feet metres centimetres conversion

March 27, 2009 by admin  
Filed under C

#include

int main()
{
float feet,metres,centimetres;
printf(”Enter the amount of feet you wish to convert.n”);
scanf(”%f”,&feet);

while(feet > 0)
{
centimetres = feet * 12 * 2.54;
metres = centimetres / 100;
printf(”%6.2f feet is equal to n”,feet);
printf(”%6.2f metresn”,metres);
printf(”%8.2f centimetresn”,centimetres);
printf(”Enter another value to be converted or n”);
printf(”enter 0 to exit.n”);
scanf(”%f”,&feet);
}
return 0;
}

fat file system information

March 26, 2009 by admin  
Filed under C

#include
#include

void main(void)
{
struct fatinfo fat;

getfatd(&fat);

printf(”Sectors per cluster %dn”, fat.fi_sclus);
printf(”Clusters per disk %un”, fat.fi_nclus);
printf(”Bytes per cluster %dn”, fat.fi_bysec);
printf(”Disk type %xn”, fat.fi_fatid & 0xFF);
}

Next Page »