数字转字符串
为什么会一直出现乱码?还有如何让numStr直接指向funcVar,感谢大大。程序代码:
#include<stdio.h> #include<stdlib.h> #pragma warning (disable:4996) char* numToStr(int num) { char* funcVar; int count = 1; int number = num; while (number / 10 != 0) { count++; number /= 10; } printf("count=%d\n", count); funcVar = malloc(sizeof(char)*count); for (int i = count-1; i >=0; i--) { funcVar[i] = (num % 10) + 48; num /= 10; } printf("funcVar =%s\n", funcVar); printf("&funcVar =%x\n\n", &funcVar); return funcVar; } int main() { char* numStr=numToStr(12345678); printf("numStr =%s\n", numStr); printf("&numStr =%x\n",&numStr); }