मैं सी प्रोग्रामिंग भाषा का उपयोग करके एक विभाजन तालिका मुद्रित करने की कोशिश कर रहा हूं, सब ठीक काम करने लगता है: खोलना और पढ़ना, लेकिन मुझे समझ में नहीं आता कि यह कचरा मूल्य क्यों प्रिंट कर रहा है।प्रिंटिंग विभाजन तालिका - सी प्रोग्राम
struct partition
{
unsigned char drive;
unsigned char chs_begin[3];
unsigned char sys_type;
unsigned char chs_end[3];
unsigned char start_sector[4];
unsigned char nr_sector[4];
};
int main()
{
int gc = 0, i = 1, nr = 0, pos = -1, nw = 0;
int fd =0;
char buf[512] ;
struct partition *sp;
printf("Ok ");
if ((fd = open("/dev/sda", O_RDONLY | O_SYNC)) == -1)
{
perror("Open");
exit(1);
}
printf("fd is %d \n", fd);
pos = lseek (fd, 0, SEEK_CUR);
printf("Position of pointer is :%d\n", pos);
if ((nr = read(fd, buf, sizeof(buf))) == -1)
{
perror("Read");
exit(1);
}
close(fd);
printf("Size of buf = %d\n and number of bytes read are %d ", sizeof(buf), nr);
if ((nw = write(1, buf, 64)) == -1)
{
printf("Write: Error");
exit(1);
}
printf("\n\n %d bytes are just been written on stdout\n", nw,"this can also be printed\n");
printf("\n\t\t*************Partition Table****************\n\n");
for (i=0 ; i<4 ; i++)
{
sp = (struct partition *)(buf + 446 + (16 * i));
putchar(sp -> drive);
}
return 0;
}
यह विभाजन तालिका के बजाय कचरा प्रिंट कर रहा है:
यहाँ कोड है।
मुझे कुछ बुनियादी समझ के मुद्दे हो सकते हैं लेकिन मैंने लंबे समय से Google के साथ खोज की लेकिन वास्तव में यह मदद नहीं की। मैंने fdisk का स्रोत कोड भी देखा लेकिन यह इस बिंदु पर मेरी समझ से परे है। क्या कोई मुझे मार्गदर्शन कर सकता है? मैं किसी को मेरी गलती को साफ़ करने और मुझे कामकाजी कोड देने की उम्मीद नहीं कर रहा हूं। बस एक वाक्य या दो - या कोई लिंक।
क्या आप 'fdisk' या अन्य विभाजन उपयोगिता के स्रोत कोड में देख पर विचार? –
@ बेसिलस्टारनकेविच स्टैरेनकेविच हां उन्होंने अपनी पोस्ट के अनुसार किया। @Adorn आपकी समस्या इस लाइन में होती है? 'printf (" \ n \ t \ t ************* विभाजन तालिका **************** \ n \ n ");'? या फिर उसके बाद आउटपुट का मतलब था? – xQuare
'ड्राइव' उपलब्ध प्रकार क्या है? –