본문/내용
memset((double *)res_list, 0, sizeof(res_list));
calc_ok = 0;
pos = 0;
printf(`====================== Calculator =====================\\n`);
printf(`종료(Q) 이전결과(P)/결과목록출력(L)/결과목록지우기(E)\\n`);
printf(`-------------------------------------------------------\\n`);
while(TRUE)
{
printf(`수식입력 : `);
fgets(src, MAX - 1, stdin);
src[strlen(src) - 1] = `\\0`;
if(is_intkey(src))
proc_intkey(src, res_list, &pos);
/* 중위표기법을 후위표기법으로 바꿈 */
if(!preproc(dest, src))
continue;
/* 후위표기법을 계산 */
res = calc(dest, &calc_ok);
if(!calc_ok)
continue;
printf(`결과값 : %lf\\n\\n`, res);
/* 결과값 저장 */
store_res(res_list, res, &pos);
}
return 0;
}
/* 키입력을 받았는지 */
int is_intkey(char *key)
{
if(confirm_key(key, `Q`))
return TRUE;
if(confirm_key(key, `L`))
return TRUE;
if(confirm_key(key, `P`))
return TRUE;
if(confirm_key(key, `E`))
return TRUE;
return FALSE;
}
/* 키값 검사 */
int confirm_key(char *key, char c)
{
if…
…