[英]The following code doesn't work .. why?
以下代码无法正常工作..
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
struct dest
{
char filename[20], keyword[20];
bool opened;
FILE * stream;
};
void display_data(const struct dest p) {
printf("Keyword: %s, Filename: %s, Used: %s\n", p.keyword, p.filename, p.opened ? "Yes" : "No");
}
int main(int argc, char const *argv[])
{
// float lon, lat;
// char info[80];
if ((argc+1) % 2) {
fprintf(stderr, "Usage: %s file_to_read file_for_unknown type file type file ...\n", argv[0]);
return 2;
}
if (access(argv[1], F_OK) == -1) {
fprintf(stderr, "File can't be accessed: %s\n", argv[1]);
return 2;
}
const short pairs = (argc-3)/2;
struct dest data[pairs];
short times = 4;
for(short i = 4; i < argc; i += 2) {
struct dest data[i-times];
data[i-times].opened = false;
strcpy(data[i-times].keyword, argv[i-1]);
strcpy(data[i-times].filename, argv[i]);
// display_data(data[i-times]);
times += 1;
}
display_data(data[0]);
return 0;
}
那就是我尝试运行它时发生的事情..
./归类为spooky.csv other.csv UFO UFOS.csv
关键字:?,文件名: @,使用:否
那没有什么意义..
我一直在努力解决问题..
我不明白问题出在哪里..
参数解析如下:
第一个参数 :程序应从中读取的文件(目前忽略)
(also, ignored in this implementation) 第二个参数 :程序应该在找到的任何未知信息处存储的 (在此实现中也被忽略)
其他参数 :它们被解析为对,第一个是关键字,第二个是文件..
对于此过滤问题,我的解决方案是创建一个结构数组,并在每个结构中存储关键字,文件名和文件io流(我暂时忽略)。
任何帮助将不胜感激..
您有2个struct dest data[]
数组。 内在的是遮蔽外在的-摆脱它。
如果您打开了警告,则编译器可能会对此发出警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.