C语言实现字符串转数字

来源:互联网 发布:工人软件 编辑:程序博客网 时间:2024/04/29 17:00
#include "stdafx.h"#include <stdio.h> #include <string.h> long fun ( char *p) {  int i, len, t;  long x=0;  len=strlen(p);  if(p[0]=='-')  { t=-1; len--; p++; }  if(p[0]=='+') { t=1; len--; p++; } else t=1;  while(*p) x = x*10-48+(*p++);    return x*t; } void main() { char s[15]; long n; printf("输入你的字符串数\n") ; gets(s); n = fun(s); printf("%ld\n",n); scanf("%d");} 


0 0
原创粉丝点击