파일이 하나 안 읽어서 그러는데 소스좀 봐 주세여
겨레
이 코드에 dec 파일이 안 읽는데여 왜인지 잘 모르겠어여 설명좀 부탁드립니다.
#includestdio.h
#includestdlib.h
int hash1 (FILE* sp);
void encrypt(FILE* sp, FILE* cip, int key);
void decrypt(FILE* sp, FILE* cip, FILE* dec, int key);
int main()
{
int key,st1;
FILE* sp;
FILE* cip;
FILE* dec;
printf(enter the key value\n);
scanf(%d, &key);
if(!(sp=fopen(cleartext.txt, r+)))
{
printf(Error opening file\n);
exit(1);
}
if(!(cip=fopen(ciphertext.bin,w+b)))
{
printf(Error opening file\n);
exit(1);
}
if(!(dec=fopen(cleartext.new,w)))
{
printf(Error opening file\n);
exit(1);
}
if(key0)
{
printf(Input error\n);
exit(1);
}
encrypt(sp,cip,key);
decrypt(sp,cip,dec,key);
st1=hash1(sp);
printf(The value of hash is %u\n,st1);
fclose(sp);
fclose(cip);
fclose(dec);
return 0;
}
int hash1(FILE* sp)
{
unsigned int hash=0,message=0;
char cd;
if(sp==NULL)
{
printf(File open error\n);
exit(1);
}
rewind(sp);
while((cd=fgetc(sp))!=EOF)
{
fseek(sp,-1,SEEK_CUR);
fread(&message,sizeof(int),1,sp);
hash=hash+message;
}
return hash;
}
void encrypt(FILE* sp,FILE* cip,int key)
{
char cd;
unsigned int message,cipher;
if(sp==NULL)
{
printf(File open error\n);
exit(1);
}
while((cd=fgetc(sp))!=EOF)
{
fseek(sp,-1,SEEK_CUR);
fread(&message,sizeof(char),1,sp);
cipher=message^key;
fwrite(&cipher,sizeof(char),1,cip);
}}
void decrypt(FILE *sp, FILE *cip, FILE *dec, int key)
{
char cd,ab;
unsigned int message,cipher;
if(cip==NULL)
{
printf(File open error\n);
exit(1);
}
rewind(cip);
while((cd=fgetc(cip))!=EOF)
{
fseek(cip,-1,SEEK_CUR);
fread(&cipher,sizeof(char),1,cip);
message=cipher^key;
fputc(message,stdout);
fputc(message,dec);
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |
2699816 | 오류 질문입니다.. (1) | 해비치 | 2025-06-29 |
2699763 | 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) | 미라 | 2025-06-28 |
2699555 | c언어 다항식을 입력을 했는데 왜 출력이 안될까요? | 피스케스 | 2025-06-27 |
2699528 | C언어 포인터연산 질문입니다. (3) | 안녕나야 | 2025-06-26 |
2699476 | 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) | 클라우드 | 2025-06-26 |