将一个数字字符串转换为一个整数

来源:百度知道 编辑:UC知道 时间:2024/09/21 19:01:46
#include<stdio.h>
#include<string.h>
long fun(char *p)
{

}
main()
{char s[6];
long n;
printf("Enter a string:\n");
gets(s);
n=fun(s);
printf("%1d\n",n);
}
请填写空格的地方,别的就不用改动了,谢谢1

#include<stdio.h>
#include<string.h>
long fun(char *p) //返回值类型没有给你变
{
long temp; //你的返回要long型的,所以定义个long型的
temp=atol(p); //atol是string.h中包含的一个方法,把字符串转成long
return temp; //返回temp
}
main()
{char s[6];
long n;
printf("Enter a string:\n");
gets(s);
n=fun(s);
printf("%1d\n",n);
}

#include<stdio.h>
#include "stdlib.h"

int fun(char *p)
{
return atoi(p);

}
main()
{char s[6];

printf("Enter a string:\n");
gets(s);
int n=fun(s);
printf("%d\n",n);
}