2016-04-01 16 views
-1

Sadece "0" onaltılık ofsetini görüntülemek için ilkinde çalışıyorum. Programın dosyayı açması için bir yol bulmaya çalışıyorum ve önde gelen bir 0x göstergesine sahip 8 basamaklı bir hex ofset'i gösteriyorum.8 basamaklı bir onaltılı aralık 0x gösteriliyor?

herhangi ipuçları/öneriler çok iyi olurdu ...

----------------------------------------------------------------------------- 
offset  0 1 2 3 4 5 6 7 8 9 a b c d e f ascii 
----------------------------------------------------------------------------- 
0x00000000 
0x00000010 
0x00000020 

vb: Ben böyle bir şey çalıştırmak zorunda çalışıyorum. Ayrıca tek tek satırlar vb printf sahip olmak yerine, afiş görüntülemek için "daha temiz" bir yol arıyoruz.

Yani, sorularım şunlardır:
  1. nasıl programı lider 0x ile ofset onaltılık görüntülemesini sağlayabilirsiniz. Bu bölüm için kodumu eklemeyi denedim ama nasıl olduğunu tam olarak anlayamıyorum, bu yüzden herhangi bir ipucu takdir edilecektir.
  2. Başlığı görüntülemenin daha temiz bir yolu var mı?

Çok teşekkür ederim.

#include <stdio.h> 
#include <stdlib.h> 
#include <sys/ioctl.h> 


int main(int argc, char** argv) 
{ 
    struct winsize terminal; 
    FILE* fp; 
    int a, c, column, row, lines; 

    ioctl(0, TIOCGWINSZ, &terminal, argv[2]); 

    fp = fopen(argv[1], "r");       //set open for argv[1] and set it to read mode 
    column = terminal.ws_col; 
    row = terminal.ws_row; 
    lines = atoi(argv[2]); 

    // printf("Rows are: %d\n", row); 
    // printf("Columns are: %d\n", column); 

    if (argc < 3)          //Argument checking, at least three to run 
    { 
     printf("You need atleast 3 arguments to run!\n"); 
     exit(1); 
    } 

    if (fp == NULL) 
    { 
     fprintf(stderr, "Error opening '%s'.\n", argv[1]);    //if not file is specified then close program and give an error 
     exit(1); 
    } 
    c = fgetc(fp);        //set c to fgetc 

    if (column < 80 || row < 20)        //if temrinal window is less than 80x20, display an error and exit 
    { 
     printf("Terminal window must be at least 80x20!\n");    //display error and close program if column criteria isn't met 
     exit(1); 
    } 

    /* 
    while(!feof(fp))         //if file is entered, display a test message (this is where later on I will show hex value) 

    { 
     printf("Good Job! You picked a file to manipulate!!\n"); 
     exit(1); 
    } 
    */ 
    if (lines == 0)          //if 0 is entered for argv[2], display all the lines, 512 byte file 
    { 
     printf("------------------------------------------------------------------------------\n"); //**this is where I try to display character/hex banner** 
     printf("offset  0 1 2 3 4 5 6 7 8 9 a b c d e f ascii\n"); 
     printf("-------------------------------------------------------------------------------\n"); 
     for (c == 0x200) ; //**This is where I try to get the 8 digit 0x hex offset** 
     { 
      fprintf(stdout, "%04x", c); 
     } 
    } 
    else if (lines == 20) 
    { 
     printf("This will print out 20 lines\n"); 
    } 
    else if (lines == 30) 
    { 
     printf("This will print out 30 lines\n"); 
    } 
    else 
    { 
     printf("Please Enter a Valid Number!\n"); 
    } 

    fclose(fp);          //close fp 

    return 0; 
} 
+1

RTF (ine) M deneyin! Printf'in sayfasını okuyun. – Olaf

cevap

4

printf("0x%08x\n", 0xDEADBEEF); 
+0

Teşekkür ederim, ofset sütunumu doldurmak için farklı hex değerleri kümesini tekrarlamak için bir 'for' döngüsü kullanmak zorunda mıyım? – Rob

+0

@Rob Bu doğru. –

İlgili konular