#include<stdio.h>
#define MAXLINELEN 1000
int power(int base,int n)
{
int i=;
int answer=;
for(i=;i<n;i++)
answer=answer*base;
return answer;
}
/*strlen函数:返回s的长度*/
int strlen(char *s)
{
int i;
i=;
while(s[i]!='\0')
++i;
return i;
}
/*getline函数*/
void getlines(char *s)
{
int i=;
int lim=MAXLINELEN;
int c;
for(i=;i<lim-&&(c=getchar())!='\n'&&c!=EOF;i++)
s[i]=c;
}
/*hexalpha_to_int函数:把单个char转换成int*/
int hexalpha_to_int(int c)
{
if(c>=''&&c<='')
c=c-'';
else if(c>='a'&&c<='z')
c=c-'a'+;
else if(c>='A'&&c<='Z')
c=c-'A'+;
return c;
}
/**/
int htoi(char s[])
{
int len;
int i;
len=strlen(s);
int answer=;
if(s[]==''&&(s[]=='X'||s[]=='x'))
{
for(i=;i<len;i++)
{
answer=hexalpha_to_int(s[i])*power(,len--i)+answer;
}
}
else
{
for(i=;i<len;i++)
{
answer=hexalpha_to_int(s[i])*power(,len--i)+answer;
printf("i:%d\n",i);
printf("hexalpha_to_int(s[i]):%d\n",hexalpha_to_int(s[i]));
printf("power(16,len-1-i):%d\n",power(,len--i));
printf("answer:%d\n",answer);
}
}
return answer;
}
main()
{
char s[MAXLINELEN];
getlines(s);
printf("%d\n",htoi(s));
}

the c programming language 2-3的更多相关文章

  1. iOS Swift-元组tuples(The Swift Programming Language)

    iOS Swift-元组tuples(The Swift Programming Language) 什么是元组? 元组(tuples)是把多个值组合成一个复合值,元组内的值可以使任意类型,并不要求是 ...

  2. iOS Swift-控制流(The Swift Programming Language)

    iOS Swift-控制流(The Swift Programming Language) for-in 在Swift中for循环我们可以省略传统oc笨拙的条件和循环变量的括号,但是语句体的大括号使我 ...

  3. iOS Swift-简单值(The Swift Programming Language)

    iOS Swift-简单值(The Swift Programming Language) 常量的声明:let 在不指定类型的情况下声明的类型和所初始化的类型相同. //没有指定类型,但是初始化的值为 ...

  4. Java Programming Language Enhancements

    引用:Java Programming Language Enhancements Java Programming Language Enhancements Enhancements in Jav ...

  5. The Swift Programming Language 英文原版官方文档下载

    The Swift Programming Language 英文原版官方文档下载 今天Apple公司发布了新的编程语言Swift(雨燕)将逐步代替Objective-C语言,大家肯定想学习这个语言, ...

  6. The Swift Programming Language 中文翻译版(个人翻新随时跟新)

    The Swift Programming Language --lkvt 本人在2014年6月3日(北京时间)凌晨起来通过网络观看2014年WWDC 苹果公司的发布会有iOS8以及OS X 10.1 ...

  7. [iOS翻译]《The Swift Programming Language》系列:Welcome to Swift-01

    注:CocoaChina翻译小组已着手此书及相关资料的翻译,楼主也加入了,多人协作后的完整译本将很快让大家看到. 翻译群:291864979,想加入的同学请进此群哦.(本系列不再更新,但协作翻译的进度 ...

  8. Questions that are independent of programming language. These questions are typically more abstract than other categories.

    Questions that are independent of programming language.  These questions are typically more abstract ...

  9. What is the Best Programming Language to Learn in 2014?

    It’s been a year since I revealed the best languages to learn in 2013. Once again, I’ve examined the ...

  10. C: Answers to “The C programming language, Edition 2”

    <The C programming language> Edition 2的习题答案地址: http://users.powernet.co.uk/eton/kandr2/index.h ...

随机推荐

  1. Unity 官方 Demo: 2DPlatformer 的 SLua 版本。

    9月份时,趁着国庆阅兵的假期,将 Unity 官方 Demo: 2DPlatformer 移植了一个 SLua 版本,并放在了我的 GitHub 账号下:https://github.com/yauk ...

  2. MySQL数据库建立外键失败的原因总结

    在MySQL数据库创建外键时,经常会发生一些错误,这是一件很令人头疼的事.一个典型的错误就是:Can’t create table... 的错误.在很多实例中,这种错误的发生都是因为mysql一直以来 ...

  3. Using Java SecurityManager to grant/deny access to system functions

    In Java it is possible to restrict access to specific functions like reading/writing files and syste ...

  4. IO(Input Output)流__字符流

    一.IO流简述------用于操作数据的 IO流用来处理设备之间的数据传输; Java对数据的操作是通过流的方式; Java用于操作流的对象都是在IO包中; 流按操作数据分为: 字节流(通用)和字符流 ...

  5. spring 最全MAVEN 依赖引入配置

    <properties> <spring.version>4.1.6.RELEASE</spring.version> </properties> &l ...

  6. springsecurity4+springboot 实现remember-me 发现springsecurity 的BUG

    前言:现在开发中,记住我这个功能是普遍的,用户不可能每次登录都要输入用户名密码.昨天准备用spring security的记住我功能,各种坑啊,吐血 . 先看下具体实现吧. spring securi ...

  7. 【转】maven 项目出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    http://blessht.iteye.com/blog/1104450 http://www.cnblogs.com/zhouyalei/archive/2011/11/30/2268606.ht ...

  8. c#调用api(FindFirstFile,FindNextFile)高效遍历目录文件【转载】

    在c#下遍历目录,应用最多的应该就是 System.IO.DirectoryInfo.GetDirectories或GetFiles了,但是当目录特别大,文件特别多时,效率不尽人意,此时我们很容易想到 ...

  9. 06 MDB将数据和dataGridView1绑定

    附件:http://files.cnblogs.com/xe2011/dataGridView1_bindingNavigator1_bindingSource1.rar 实现功能 对.MDB文件进行 ...

  10. Swipecards

    https://github.com/Diolor/Swipecards https://github.com/kikoso/Swipeable-Cards