首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

如何把这个程序换成整形类型的程序

2012-02-15 
怎么把这个程序换成整形类型的程序啊#include stdio.h#include stdlib.h#include malloc.h#include

怎么把这个程序换成整形类型的程序啊
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
int   main()
{
char   *s;
if((s=(char*)malloc(10*sizeof(char)))==NULL)
{
printf( "not   enough   memorg   to   allocte   bufer.\n ");
exit(1);
}
strcpy(s, "hello ");
printf( "string   is   %s\n ",s);
free(s);
}
  这个程序我今天终于看懂了意思
    但是我试着把char换成int的怎么换都不会   高手指点下啊   如果程序要求是在这个程序里是整型类型的     而不是字符串的   又该怎么编啊

[解决办法]
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
int main()
{
int *s;
if((int=(int*)malloc(10*sizeof(int)))==NULL)
{
printf( "not enough memorg to allocte bufer.\n ");
exit(1);
}
s[0] = 0;
printf( "s[0] is %d\n ",s[0]);
s[1] = 1;
printf( "s[1] is %d\n ",s[1]);
…………
free(s);
}

热点排行