배열 출력 관련 질문드립니다~
핀아
질문 제목 : 배열 출력 관련 질문드립니다~질문 내용 :
gets()로 입력받은 data의 길이가 짝수일때는 상관 없는데 홀수일때 출력을 해주기 위해
for문 안에 조건을 데이터길이 / 2 +1 을 했더니 짝수일때 빈배열이 출력이 되더군요..
-------------------------보여지는 모습---------------------------
홀수일때는
------------
|fo: 466f |
|ro:726f |
|uz: 757a|요렇게 나오는데
|an:616e |
|1: 3100|
------------
짝수일때
------------ ------------
|fo: 466f||fo: 466f |
|ro:726f | |ro:726f |
|uz: 757a| 요걸 원하는데 |uz: 757a| 요렇게 마지막빈배열이 출력되더라구요;;
|an:616e | |an:616e |
------------ |:f f f f f f f f|
------------
이걸 안보이게 하려고 하는데.. 방법이 있을까요?
밑에 소스코드 첨부하겠습니다.~
-------------------------소스코드---------------------------
void make_checksum(char *inputdata)//checksum 생성(sender)
{
charbitseq[256];//bit 순서를 출력하기 위한 버퍼배열
gets(inputdata);
fflush(stdin);
sizedata = strlen(inputdata);//입력받은 data 길이
for(index_cnt = 0; index_cnt datalength; index_cnt++)
checkdata[index_cnt] = -1;//초기화.
&;//-1 로 초기화
for(index_cnt = 0; index_cnt sizedata / 2 ; index_cnt++)
{//16bit 단위로 나누어서 저장시킴
checkdata[index_cnt] = inputdata[index_cnt * 2];
checkdata[index_cnt] = checkdata[index_cnt] 8;
checkdata[index_cnt] += inputdata[(index_cnt * 2) + 1];
}
if(sizedata % 2 == 1)//입력받은 data 의 길이가 홀수일 경우,마지막이 8bit 만 있기 때문에 0으로 채운 8bit를 추가해줌(padding)
{
checkdata[index_cnt] = inputdata[index_cnt * 2];
checkdata[index_cnt] = checkdata[index_cnt] 8;
}
printf(\n\n2글자 단위로 bit 정보 출력\n -----------------\n);
for( index_cnt = 0; index_cnt sizedata / 2 + 1; index_cnt++ )// 2글자 단위로 bit 정보를 출력
{
memset(bitseq, 0, sizeof(char) * 10);
itoa(checkdata[index_cnt], bitseq, 16);
printf(| %c%c : %s | \n, inputdata[index_cnt * 2], checkdata[index_cnt], bitseq);
}
-
채련
감사합니다 ^^
-
일본어못해요
sizeData가 홀수일 때만 1을 더하세요.
마침, 위에 sizeData가 홀수인지 검사하는 부분이 있네요.