下面这个程序是因为文件路径的问题么?????
程序代码:
#include <stdio.h> #define FALSE 0 #define TRUE 1 #define MAX_BUF_LEN 1500 #define SOH 0x01 #define EOT 0x04 #define ESC 0x1B typedef int Status; typedef struct StuffingString{ unsigned char buf[MAX_BUF_LEN]; unsigned int len; }*PStuffingString; Status byte_stuffing(PStuffingString psin,PStuffingString psf){ unsigned int i = 0; psf->len = 0; while(i<psin->len) { if(psin->buf[i]==SOH||psin->buf[i]==EOT||psin->buf[i]==ESC) psf->buf[psf->len++]=ESC; psf->buf[psf->len++]=psin->buf[i++]; } return TRUE; } Status byte_unstuffing(PStuffingString psf,PStuffingString psd){ unsigned int i = 0; psd->len = 0; while(i<psf->len) { if(psf->buf[i]==ESC) { i++; if(psf->buf[i]!= SOH && psf->buf[i]!= EOT && psf->buf[i]!= ESC) return FALSE; } psd->buf[psd->len++]=psf->buf[i++]; } return TRUE; } Status input(char f[],PStuffingString psin){ FILE *fp; psin->len = 0; if((fp = fopen(f,"r"))==NULL) return FALSE; while(fscanf(fp,"%2X",&psin->buf[psin->len++])!=EOF); psin->len--; if(fclose(fp)) return FALSE; return TRUE; } Status output(char f[],PStuffingString psout){ FILE *fp; unsigned int i = 0; if((fp = fopen(f,"w"))==NULL) return FALSE; while(i<psout->len) { if(psout->buf[i]<0x10) fprintf(fp,"0"); fprintf(fp,"%0X",psout->buf[i++]); } if(fclose(fp)) return FALSE; return TRUE; } void fun_01() { StuffingString sin,sf,sd; if(input("C:\input.txt",&sin)==TRUE) { if(byte_stuffing(&sin,&sf)==TRUE) { output("C:\output_f.txt",&sf); if(byte_unstuffing(&sin,&sf)==TRUE) { output("C:\output_d.txt",&sd); printf("byte-stuffing/unstuffing successful!\n"); } } } } void main () { fun_01(); }这是一个用字节填充法解决透明传输的一个模拟。谁知道为什么运行没结果。。。。
input.txt文件里的内容是:
AC00013C5604201B76