c语言:文件操作,简单压缩程序问题疑惑

#include
#include
#include
int main(int argc, char *argv[])
{
FILE *in, *out;
int ch;
char name[LEN];
int count = 0;
if (argc < 2)
{
fprintf(stderr, "usage:%s filename \n", argv[0]);
exit(EXIT_FAILURE);
}
if ((in = fopen(argv[1], "r")) == NULL)
{
fprintf(stderr, "i couldn't open the file \"%s\"\n", argv[1]);
exit(EXIT_FAILURE);
}
strncpy(name, argv[1], LEN - 5);
name[LEN - 5] = '\0';
strcat(name, ".red");
if ((out = fopen(name, "w")) == NULL)
{
fprintf(stderr, "can't create output file .\n");
exit(3);
}
while ((ch = getc(in)) != EOF)
if (count++ % 3 == 0)
putc(ch, out);
if (fclose(in) != 0 | fclose(out) != 0)
fprintf(stderr, "Error in closing files \n");
return 0;

}图片说明

char name[LEN];

LEN 未定义。。。
先把这个问题解决了。。。

define一下LEN就行了

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 32
int main(int argc, char *argv[])
{
    FILE *in, *out;
    int ch;
    char name[LEN];
    int count = 0;
    if (argc < 2)
    {
        fprintf(stderr, "usage:%s filename \n", argv[0]);
        exit(EXIT_FAILURE);
    }
    if ((in = fopen(argv[1], "r")) == NULL)
    {
        fprintf(stderr, "i couldn't open the file \"%s\"\n", argv[1]);
        exit(EXIT_FAILURE);
    }
    strncpy(name, argv[1], LEN - 5);
    name[LEN - 5] = '\0';
    strcat(name, ".red");
    if ((out = fopen(name, "w")) == NULL)
    {
        fprintf(stderr, "can't create output file .\n");
        exit(3);
    }
    while ((ch = getc(in)) != EOF)
    if (count++ % 3 == 0)
        putc(ch, out);
    if (fclose(in) != 0 | fclose(out) != 0)
        fprintf(stderr, "Error in closing files \n");
    return 0;

}