myint.c
来自「压缩包里面的都是精致的基本C语言小程序」· C语言 代码 · 共 77 行
C
77 行
#include <stdio.h>#include <stdlib.h>#include "mystdlib.h"#include "error.h"#include "myint.h"static int maxSize = 1000;struct myint{ int i;};myint newMyint (int i){ myint mi = checkedMalloc (sizeof (*mi)); mi->i = i; return mi;}str intToString2 (int n){ char a[100]; int temp[100]; int size = -1; char sign = '+'; if (n < 0) sign = '-'; int absn = abs (n); int mod = 0; while (absn > 9) { mod = absn % 10; absn = absn / 10; temp[++size] = mod; } if (absn>=0) temp [++size] = absn; //for (int t=0; t<=size; t++) //printf ("size=%d, %d\n", size, temp[t]); if ('-'==sign) { for (int j=size; j>=0; j--) a[size-j+1] = temp[j] + 48; a[0] = '-'; a[size+2] = '\0'; } else { for (int j=size; j>=0; j--) a[size-j] = temp[j] + 48; a[size+1] = '\0'; } return newStr (a);}str intToString (long i){ char *temp; temp = checkedMalloc (maxSize * sizeof (char)); sprintf (temp, "%ld", i); if (! (strValid (temp, maxSize))) exception ("space not enought: myint.c\n"); str sss = newStr (temp); checkedFree (temp); return sss;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?