嗨,我正在尝试编写一个程序,可以逐行,逐字或逐字符地比较两个文件.它必须能够读入命令行选项"-l -w -i或 - "...如果选项是-l,它会逐行比较文件.如果选项是-w,它会逐字比较文件.如果选项是 - 它会自动假定下一个arg是第一个文件名.如果选项是-i,则以不区分大小写的方式对它们进行比较.否则,它默认按字符比较文件
只要-w和-l没有同时输入且没有多于或少于2个文件,输入选项的时间并不重要.
我甚至不知道从哪里开始解析命令行参数.请帮忙 :(
所以这就是我想出的所有代码.我还没有错误检查它,但我想知道我是否以过于复杂的方式写东西?
/*
* Functions to compare files.
*/
int compare_line();
int compare_word();
int compare_char();
int case_insens();
/*
* Program to compare the information in two files and print message saying
* whether or not this was successful.
*/
int main(int argc, char* argv[])
{
/*Loop counter*/
size_t i = 0;
/*Variables for functions*/
int caseIns = 0;
int line = 0;
int word = 0;
/*File pointers*/
FILE *fp1, *fp2; …Run Code Online (Sandbox Code Playgroud)