|
우선
int count =3;
char buf[count];
이런식으로 쓰면
//--
[BCC32 Error] Unit2.h(52): E2313 Constant expression required
Full parser context
File1.cpp(7): #include Unit2.h
Unit2.h(13): class CompressFile
Unit2.h(66): decision to instantiate: void CompressFile::unCompressFile(char *,char *)
--- Resetting parser context for instantiation...
Unit2.h(41): parsing: void CompressFile::unCompressFile(char *,char *)
//--
란 에러가 뜨네요. 그래서 상수 값을 쓰라는 건가 보다라고 생각해서
const int count =3;
char buf[count];
이런식으로 하니 에러가 안났습니다.
드디어 질문 파일의 길이를 구하는데
FILE* file;
file = fopen("파일명","wb");
if(file == NULL) printf("error");
const int fileLength = filelength(fileno(file));
char buf[fileLength];
라고 하면 될 줄 알았는데 맨 위와 같은 에러가 뜹니다. 그 이유를 알고 싶습니다. -- 알고 보니 반환형이 long 형이네요
그럼 다음 질문
실제로 char buf[fileLength];를 char* buf = (char*)malloc(fileLength) 라고 하면 아무 문제가 없지만 긍금한 것은
그냥 배열로 만드는 방법은 없을까요?
|