현재 간단한 간단한 일회용 패드 프로그램을 작성 중입니다. keyfile
이 source
파일보다 작을 때 사용자에게 경고하고 싶지만 실행하면 내 프로그램이이를 무시합니다. C 프로그램이 if 문의 문을 무시하고 있습니다.
/* Check if keyfile is the same size as, or bigger than the sourcefile */
if(sizeof keyfile < sizeof sourcefile)
{
printf("Source file is larger than keyfile.\n");
printf("This significantly reduces cryptographic strength.\n");
printf("Do you wish to continue? (Y/N)\n");
scanf("%c", &ans);
if(ans == 'n' || ans == 'N')
{
return (1);
}
if(ans == 'y' || ans == 'Y')
{
printf("Proceeding with Encryption/Decryption.\n");
}
나는 문제가 내 사용
sizeof
에게 있습니다 의심하지만 난 다른 옵션에 대해 몰라? 작동하도록 코드를 어떻게 바꿀 수 있습니까?
편집 :
/* Get size of sourcefile. */
if((sourcefile = fopen(argv[1], "rb"))== NULL)
{
printf("Can't open source file.\n");
printf("Please enter a valid filename.\n");
printf("USAGE: OTP <source file> <output file> <keyfile>\n");
return (1);
}
fflush(sourcefile);
fstat(fileno(sourcefile), &statbuf);
fclose(sourcefile);
/* Get size of keyfile. */
if((keyfile = fopen(argv[3], "rb"))== NULL)
{
printf("Can't open keyfile.\n");
printf("Please enter a valid filename.\n");
printf("USAGE: OTP <source file> <output file> <keyfile>\n");
return(1);
fflush(keyfile);
fstat(fileno(keyfile), &keybuf);
fclose(keyfile);
}
과의 첫 번째 줄 경우를 변경 : 내 능력의 최선을 fstat
를 추가하는 시도,하지만 여전히 같은 방식으로 반응 ... 여기에 내가 무슨 짓을 문이 무시 됨 :
if((keybuf.st_size) < (statbuf.st_size))
왜 프로그램에서 여전히 무시되고 있습니까?
시간을내어 답변 해 주신 분들께 감사드립니다.
http://stackoverflow.com/questions/238603/how-can-i-get-a-files-size-in-c – Paulpro
컴파일 타임에 결정이 내려지기 때문에 변수' keyfile'과'sourcefile'은 아마 문제가되지 않을 것입니다, 그러나 완전을 위해, 당신은 그렇게해야합니다. –
사람들이 그것을보고 싶어하고 가독성을 위해 다른 질문을 만드는 것을 고려하십시오. – tomahh