// floatToString_function.cpp : 定义控制台应用程序的入口点。
//
#include "StdAfx.h"
#include<conio.h>
#include<stdio.h>
#include <string.h>
void floattostring(float dec,char *s)
{
int i=0,j;
char temp;
int ipart;
ipart=int(dec*1000);
printf("String is: %s",s);
while(ipart)
{
s[i]=ipart%10+'0';
ipart=ipart/10;
i++;
}
for(j=i-1;j>=i/2;j--)
{
temp=s[j];
s[j]=s[i-j-1];
s[i-j-1]=temp;
}
}
int main()
{
float ii;
// char fs[20] = {NULL} ;
char fs[] = {NULL} ;
// char *fs = new char;
// *fs =NULL;
printf("please input a number: ");
scanf("%f",&ii);
floattostring(ii,fs);
printf("String is: %s",fs);
// delete fs;
getch();
return 0;
}
char fs[20] = {NULL} 给字符数组里的每一个字符都为NULL;
char fs[20] = "NULL" 把NULL当做一个字符串常量付给fs[20];
char fs[] = "NULL" ; 把NULL字符串赋给fs,fs的长度为5;
char *fs = new char; *fs =NULL; fs为指向char变量的指针, 后给指针为空;
char *fs = new char; *fs ={NULL}; 赋值错误,不能识别;
char *fs = new char;*fs ='NULL'; 字符型赋值正确;
char *fs = new char;*fs =“NULL”; 不能把字符串常量赋值给字符型变量;