Thread: got confused which specifier to use ?!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497

    got confused which specifier to use ?!

    hello , there are some problems here !
    first when i try to compile these codes i get negetive numbers while im supposed to get positive ones! i used different specifiers such as "%ld, %d , %i, %u ,and etc .and all i knew in order to check if one could give me a close answer! but no luck ...
    the number i should get is sth like 1,475,365 or so , that according to my knowledge an unsigned long should give me that! or i can get such number with a "long" specifier ... any way when i try to use a long specifier i only get an irrelevant number of 136,465,321 or stuff like that ! well im using an ancient compiler name TC version 3 .. cause i need to program under dos and 16 bit based progs .. im tring on these .so a compiler like Tc can do the job for me ..but as you all know its only supports C90 standard! and i have difficulties using INT_MAX and stuff like that ...
    please help me on this

    and the second problem is that ..when i palce the whole structure above the "main() function " in order to use other functions to organize the whole program ... it just wont run ! it compiles without any problem ! but when i press "Enter" to start the program it just exits ! why ? !! is there any way to use functions ?
    (if you notice you will see i commented a function that used to call FAT infos to be printed on screen ! thats why i commented it ! )

    well, ill be really very happy if you help me n this

    thanx in advance and i appreciate your kind help

    Code:
    //In the name of GOD
    
    //version 0.1.0
    
    /* Using Structure to hold data+Floppy disk stats
    Original code :A Piece of COde that extracts floppy disk geometry information, 
    its  been writen in pure C and has been tested and ran seccessfully under TC 3 ...
    Added session:Floppy Disk Stat reader!, it is intended to show the floppy
    -disk information rather than its FAT info or floppy geometry!
     Cod3r :Seyyed HOssein hasn pour in NOvember 12th 2007
     www.PersianOs.org*/
    //##################Define Session######################
    typedef unsigned char BYTE;
    typedef short  int     WORD;
    typedef int          DWORD;
    //###################Main Session#######################
    void profile_1(void);
    //void FLOPPY_STATS(void);
    #include <stdio.h>
    #include <process.h>
    #include <string.h>
    #include <conio.h>
    #include <dos.h>
    
    
     int main(void)
    {
    //###################Structure To hold data#############
    struct Floppy_DISK_INFORMATION
    {
       BYTE jumpCode[3];
       BYTE oemName[8];
       WORD bytes_Sector;
       BYTE sec_Cluster;
       WORD size_Sector_Reserved;
       BYTE fatCount;
       WORD Max_Root_Entry;
       WORD Total_Sector_FS;
       BYTE Media_Type;
       WORD sectors_per_fat;
       WORD sectors_per_track;
       WORD total_Head_Count;
       DWORD no_Sectors_Before_Part;
       DWORD no_Sector_FS32;
       BYTE BIOS_13h_Drive_No;
       BYTE reserved;
       BYTE ext_Boot_Part_Signature;
       DWORD vol_Serial_Number;
       BYTE vol_Label_Name[11];
       BYTE FS_Type[8];
       BYTE boot_Code[448];
       WORD signature;
    } fdi;
    
    //###################Declaring variables#################
        int j,i,start,sector,bad_counter=0,sector_counter=0;
        char buf[512];
        profile_1();
        sector =0;
    
    //#################Reading From Floppy Disk #############
        if (absread (0, 1, sector,&fdi)!=0)
        {
        printf ("An Error Has Occurred!");
        exit(1);
           }
           printf("Read Seccessfully !\n");
    
    //################Printing The Infos on Consol##############
    
       printf("Floppy Disk Information: \n");
       printf("===========================\n");
       printf("Assembly Instruction to jump to Boot code: 0x%x\n",
          fdi.jumpCode);
       printf("OEM Name: %s\n",&fdi.oemName);
       printf("Bytes per sector: %d\n",fdi.bytes_Sector);
       printf("Sector per cluster: %d\n", fdi.sec_Cluster);
       printf("Size in sector for reserved area(Boot Sector): %d\n",
          fdi.size_Sector_Reserved);
       printf("Number of FATs(File Allocation Table): %d\n",
          fdi.fatCount);
       printf("Number of files for root directory: %d\n",
           fdi.Max_Root_Entry);
       printf("Number of Sectors in File System: %d\n",
          fdi.Total_Sector_FS);
       printf("Media Type\n(According to Microsoft,0xF8 == fixed disk and 0xF0 == Removable disk):0x%x\n", fdi.Media_Type);
       printf("Number of Sectors for each FAT: %d\n",
          fdi.sectors_per_fat);
       printf("Sectors per track: %d\n", fdi.sectors_per_track);
       printf("Number of head in storage device: %d\n",
          fdi.total_Head_Count);
       printf("BIOS INT13h Drive number: 0x%x\n", fdi.BIOS_13h_Drive_No);
       printf("Volume Serial Number: %d\n", fdi.vol_Serial_Number);
       printf("Volume label Name: %s\n", fdi.vol_Label_Name);
       printf("Boot Sector Signature: 0x%x\n", fdi.signature);
    
    
    
    
    //#######################FLP STATS#################
    
    for(i=0;i<=fdi.Total_Sector_FS;i++){
    if (absread (0, 1,i,&fdi)!=0) //&fdi is a  memory buffer that we will use to hold data
      { bad_counter++;}//number of bad sectors
     {
     sector_counter++;//number of used sectors
               }
    
    
    }
    //############declaring x and temp ###############
        unsigned long int x=fdi.bytes_Sector*fdi.Total_Sector_FS,y=fdi.bytes_Sector;
        unsigned long temp = (unsigned long)fdi.bytes_Sector * (unsigned long)fdi.Total_Sector_FS;
    //################################################
    
       printf("\n         ################## FLOPPY_STATS###############");
    
        printf("\n\nYour Floppy Disk Stats are as follows\n");
    
    
    printf("You have currently %ld Bytes on your Disk\n",x);
    
    printf("You have currently  %d Sectors of your disk space occupied\n",sector_counter);
    
    printf("You have currently %d bad sectors in YOur Floppy Disk\n",bad_counter);
    
    printf("Total used space on YOur Floppy disk is %d %% \n",(y*sector_counter)/100);
    
    printf("Total Free space on Your Floppy disk is %d %% \n",(x)-(y*sector_counter)/100);
    printf("\n\nX= %d %ul %i %li\n\n",x,x,x,x);
    printf("YOu have currently %ld Bytes on your disk",temp);
    
    //###################End of Cods#############################
    
    
    
    printf("\n\n                 Programed By Seyyed Hossein Hasan Pour\n");
    printf("                         December 12th 2007 ");
    printf("\n                  http://www.codeguru.com/forum ");
    
    
    
         getch();
         return 0;
        }
    
    //############This will pirnt the coder info ################
    
    void profile_1(void)
    {   int k;
        clrscr();
        gotoxy(27,5);
        printf("In the name of God\n");
       gotoxy(22,7);
        printf("A S.Hossein hasan pour Project\n\n");
        printf ("This program will show you the information stored on sector 0 of the Floppy Disk\n\n                        
    (FAT TABLE INFORMATION).\n\n\n              if you are ready press any key to continue ");
        for (k=0;k<=3;k++){
        //delay(50);
        printf(".");       }
        getch();
        }
    Last edited by Masterx; 12-22-2007 at 12:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Confused with array size
    By desmond5 in forum C Programming
    Replies: 4
    Last Post: 12-04-2007, 05:14 PM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM