C语言问题 创建 Borts 文件

这个要怎么做?编写一个 C 程序,create_borts_file,它接受 3 个参数:一个文件名,整数范围的开始,以及整数范围的结尾;并创建一个包含指定borts 的同名文件。

img

img

img

代码如下:

#include <stdio.h>
#include <stdlib.h>
union ut
{
    unsigned short t;
    unsigned char buf[2];
};
int main(int argc, char *argv[])
{
    int i,start,end;
    char ch;
    union ut os,ot;
    os.t = 1;

    if(argc != 4) 
    {
        printf("参数不满足要求"); //C语言参数包含程序名
        return 0;
    }
    FILE *fp = fopen(argv[1],"wb"); //以写二进制方式打开文件
    if (fp == 0)
    {
        printf("%s文件打开失败\n",argv[1]);
        return 0;
    }
    start = atoi(argv[2]);
    end = atoi(argv[3]);
    
    for (i=start;i<=end;i++)
    {
        ot.t = i;
        if(os.buf[0] == 0x00)
        {
            fwrite(ot.buf,2,1,fp);
        }
        else
        {
            ch = ot.buf[0];
            ot.buf[0] = ot.buf[1];
            ot.buf[1] = ch;
            fwrite(ot.buf,2,1,fp);
        }
    }
    fclose(fp);
    return 0;
}