ورود

View Full Version : چراچنین نتیجه ای بدست میاد ؟



Master.
جمعه 19 بهمن 1386, 08:47 صبح
سلام .مدتها پیش برنامه ای نوشتم که اطلاعات جدول فت فلاپی رو میداد .. بعد از مدتی خواستم تعمیمش بدم و اطلاعات دیگری بهش اضافه کنم ..که به مشکلاتی برخوردم ..یکی از مشکلات گرفتن اعداد منفی بود که انتظارش رو نداشتم .مثلا حتی با استفاده از لانگ اینت و یا آن سایند لانگ اینت هم نتیجه مثبت رو نمیگرفتم ... بعدازمدتی برای حل مسئله در codeguru مسئله ام رو مطرح کردم که در آخر رسیدیم به اینکه برم و از Inspect value کامپایلر استفاده کنم و ببینم چجوریاست .. از طرفی خوب هر چه سی کردم از این اینسپت توروبو سی سر در بیارم نشد کهنشد ... الان اینجام که مشکلم رو مرتفع کنم با کمک شما دوستان عزیز
مشکل دیگه ای که بهش برخورده بودم .این بود که اگه من استراکچرم رو بالای main تعریف میکردم .زمانی که برای اجرای برنامه سعی میکردم تنها یه صفحه سیاه می اومد و میرفت در حالی که کد ها همه مرتب و صحیح بودند .. وقتی میومد زیر تابع اصلی درست میشد ..این هم دلیل تعریف استراکچر زیر main() ..اگه کسی تونست بفهمه چرا این اتفاق میوفته و بهم بگه ممنون میشم ...

برنامه زیر رو لطفا مورد عنایت قرار بدید و ممنون از کمکتون ...


//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); /* Keep indentation consistent! */
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); /* Keep indentation consistent! */
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();
}

SMRAH1
دوشنبه 06 اسفند 1386, 09:46 صبح
سلام
احتمالا اشکال از تعریف نوع است.کد پایین رو با کی توی برنامه عوض کن

typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;

موفق باشی