]> git.sur5r.net Git - cc65/blob - test/val/lib_common_atoi.c
goto.c warning fix for implicit truncation
[cc65] / test / val / lib_common_atoi.c
1 /*
2   !!DESCRIPTION!! A small test for atoi. Assumes twos complement
3   !!ORIGIN!!
4   !!LICENCE!!
5   !!AUTHOR!!
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <limits.h>
12 #include <errno.h>
13
14 static unsigned int Failures = 0;
15
16 static void CheckAtoi (const char* Str, int Val)
17 {
18     int Res = atoi (Str);
19     if (Res != Val) {
20         printf ("atoi error in \"%s\":\n"
21                 "  result = %d, should be %d\n", Str, Res, Val);
22         ++Failures;
23     }
24 }
25
26 int main (void)
27 {
28     CheckAtoi ("\t +0A", 0);
29     CheckAtoi ("\t -0.123", 0);
30     CheckAtoi ("  -32  ", -32);
31     CheckAtoi (" +32  ", 32);
32     CheckAtoi ("0377", 377);
33     CheckAtoi (" 0377 ", 377);
34     CheckAtoi (" +0377 ", 377);
35     CheckAtoi (" -0377 ", -377);
36     CheckAtoi ("0x7FFF", 0);
37     CheckAtoi (" +0x7FFF", 0);
38     CheckAtoi (" -0x7FFF", 0);
39     printf ("Failures: %u\n", Failures);
40
41     return Failures;
42 }