zoukankan      html  css  js  c++  java
  • MyOD

    MyOD

    od -tx -tc 功能

    实现效果

    myod.c 代码(可将tx,tc函数单独贴在另外两个.c文件中)

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ncurses.h>
    
    void tc(FILE *file);
    void tx(FILE *file);
    
    int main(int argc,char *argv[]){
    	initscr();
    	FILE *file=fopen("./main.c","r");
    	tx(file);
    	rewind(file);
    	tc(file);
    	refresh();
    	getch();
    	endwin();
    	return 0;
    }
    
    void tc(FILE *file)
    {
    	move(1,0);
    	refresh();
    	char ch[18];
    	int i=0,j=0;
    	while(fgets(ch,17,file)!=NULL){
    	printw("       ");
    	j++;
    	for(i=0;i<16;i++){
    		if(ch[i]=='
    '){   
    			i++;
    			printw(" ");
    			printw("\n");
    		}
    		if(ch[i]=='	'){
    			if(ch[i+1]!='	'){
    				i++;
    			}
    			printw(" ");
    			printw("\t ");
    		}
    		if(ch[i]=='')
    			break;
    		if(ch[i]!='	'){
    			printw("  %c ", ch[i]);
    		}
    	}
    	move(1+j*2,0);
    	}
    }
    
    void tx(FILE *file)
    {
    	//Initialize the coordinates
    	//Set the position
    	move(0,0);
    	refresh();
    	char ch[18];
    	int i,j=1;
    	while(fgets(ch,17,file)!=NULL){
    		printw("%07o",16*(j-1));
       		for(i=0;i<16;i++){
    			if(i%4==0){
    				printw("       ");
    			}
       			if(ch[i]=='
    '){
       				i++;
       			        printw("%02x",'
    ');
       			}
       			if(ch[i]=='')
       				break;
       			printw("%02x",ch[i]);
    			if(i%4==3){
    				printw(" ");
    			}
       		}
       		move(j*2,0);
       		j++;
    	 }
    	 printw("%07o",16*(j-1)+i);
    }
    
    
  • 相关阅读:
    c++ string 的注意事项
    vim 高级技巧
    常用工具
    网络安全测试工具
    RMQ ST算法
    高精度模板
    CodeForces
    CodeForces
    线段树初探
    树状数组初探
  • 原文地址:https://www.cnblogs.com/treebeard123/p/9693899.html
Copyright © 2011-2022 走看看