int main(int argc, char **argv){
// If the user does not have the right amount of arguments exit the program and display message
if(!(argc >= 2)){
printf("Usage: %s -l -c -w -L <filenames>");
exit(-1);
}
size_t iscFlag = 0;
size_t islFlag = 0;
size_t iswFlag = 0;
size_t isLFlag = 0;
FILE *src;
puts("Work work");
// For loop that checks for all the flags
int i;
for(i = 1; i < 5; i++){
if(strcmp(argv[i], "-c") == 0){
iscFlag = 1;
}else if(strcmp(argv[i], "-l") == 0){
islFlag = 1;
}else if(strcmp(argv[i], "-w") == 0){
iswFlag = 1;
}else if(strcmp(argv[i], "-L") == 0){
isLFlag = 1;
}
}
我试图让for循环来检查标志重新在UNIX型终端wc命令的简单。任何人都知道for循环是怎么回事?我得到了一个分段错误。还有更多的代码,但我只是发布了一部分代码。ç段错误的for循环
在此先感谢。
OH我是个白痴。我想我发现问题在发布后的几秒钟内。我只是在做./wc -w文件名,所以循环检查超出范围。 –
不要忘记printf的参数:你使用%s而不带参数。下一个可能的段错误 – ckruse