#include <stdio.h> // sprintf
#include <math.h>
+#include <stdlib.h>
#include <windows.h>
#include <tchar.h>
int len;
TCHAR *s;
HGLOBAL hGlobalMemory;
- PSTR pGlobalMemory;
+ LPTSTR pGlobalMemory;
if (!(len = _tcslen(calc.display)))
return 0;
case TEXT('\x16'): // Ctrl+V Paste
{
TCHAR *s;
- int c;
+ TCHAR c;
int cmd = 0;
- int size = 0;
- int i = 0;
+ size_t size = 0;
+ size_t i = 0;
HGLOBAL hGlobalMemory;
LPTSTR pGlobalMemory;
void calc_buffer_display(CALC *calc) {
TCHAR *p;
TCHAR s[CALC_BUF_SIZE];
- TCHAR r[CALC_BUF_SIZE] = TEXT("0");
int point=0;
calcfloat real;
else {
int i = 0;
int lz = 0;
- calcfloat r;
int exp = 0;
- r = calc_atof(calc->buffer, calc->numBase);
- _stprintf(s, FMT_DESC_EXP, r);
+ real = calc_atof(calc->buffer, calc->numBase);
+ _stprintf(s, FMT_DESC_EXP, real);
// remove leading zeros in exponent
p = s;
while (*p) {
if (!point && calc->numBase == NBASE_DECIMAL)
_tcscat(s, TEXT("."));
- if (*s == TEXT('.')) {
- _tcscat(r, s);
- _tcscpy(calc->display, r);
- }
- else {
- _tcscpy(calc->display, s);
- }
+ if (*s == TEXT('.'))
+ _tcscpy(calc->display, TEXT("0"));
+ else
+ calc->display[0] = 0;
+ _tcscat(calc->display, s);
}
}
InvalidateRect(calc->hWnd, NULL, FALSE);
r[i++] = c;
if (x++ % 3 == 0)
r[i++] = TEXT(',');
- if (n == -1)
+ if (n == 0)
break;
}
else {
calc.memory = calc_atof(calc.buffer, calc.numBase);
}
+ return 0;
}
- return 0;
}
- break;
+ // fall through for Enter processing
- // fall through for Enter processing ... but there is a bug here in Ctrl+M vs. Return
case TEXT('='):
{
calcfloat r = calc.operand;