字符串反转my_strRev.c:
/*********************************************************************************
* Copyright: (C) 2015 songyong
* All rights reserved.
*
* Filename: strRev.c
* Description: This file
*
* Version: 1.0.0(2015年09月18日)
* Author: sky
* ChangeLog: 1, Release initial version on "2015年09月18日 14时06分34秒"
*
********************************************************************************/
#include
#include
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
int main (int argc, char **argv)
{
char *strRev(char *s);
char str[] = "abcdefg";
printf("str :%s\n",str);
//strRev(str);
printf("after change, str:%s\n",strRev(str));
return 0;
} /* ----- End of main() ----- */
char *strRev(char *s)
{
char temp;
char *front = s;
char *end = s + strlen(s)-1;
while(end > s)
{
temp = *s;
*s = *end;
*end = temp;
--end;
++s;
}
return front;
}
/*********************************************************************************
* Copyright: (C) 2015 songyong
* All rights reserved.
*
* Filename: my_strlen.c
* Description: This file
*
* Version: 1.0.0(2015年09月18日)
* Author: sky
* ChangeLog: 1, Release initial version on "2015年09月18日 15时59分49秒"
*
********************************************************************************/
#include
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
int main (int argc, char **argv)
{
char a[] = "1234";
printf("a[] = %d\n",my_strlen(a));
return 0;
} /* ----- End of main() ----- */
int my_strlen(char *s)
{
int n = 0;
while(*s)
{
n++;
s++;
}
return n;
}
/*********************************************************************************
* Copyright: (C) 2015 songyong
* All rights reserved.
*
* Filename: atoi.c
* Description: This file
*
* Version: 1.0.0(2015年09月18日)
* Author: sky
* ChangeLog: 1, Release initial version on "2015年09月18日 14时38分15秒"
*
********************************************************************************/
#include
#define TEN 10
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
int main (int argc, char **argv)
{
char str[] = "123...hello world!";
printf("str atoi :%d\n",atoi(str));
return 0;
} /* ----- End of main() ----- */
int power(int base,int exp)
{
if(exp == 0)
return 0;
return base*power(base,exp-1);
}
int my_atoi(const char *s)
{
int n = 0;
int exp = 0;
const char *t = NULL;
for( ;*s ==' '|| *s == '\t'|| *s == '\n';s++)//首先找到第一个非空字符;
;
if( *s < '0' && *s > '9')//判断是否是数字字符;
return 0;
for(t = s; *t >= '0' && *t <= '9'; ++t)//找到这串数字字符后的第一个非数字字符;
;
t--;//最后一个数字字符的位置;
while(t >= s)
{
n += (*t-48)*power(TEN,exp);//1的ASIIC为1,’1‘的ASIIC为49;将原来数字字符串转换后的值换算成整数;
t--;
exp++;
}
return n;
}
/*********************************************************************************
* Copyright: (C) 2015 songyong
* All rights reserved.
*
* Filename: huiwen.c
* Description: This file
*
* Version: 1.0.0(2015年09月13日)
* Author: sky
* ChangeLog: 1, Release initial version on "2015年09月13日 14时40分53秒"
*
********************************************************************************/
#include
#include
#define LEN 100
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
int main (int argc, char **argv)
{
char str[LEN];
int len, flag, i;
while(scanf("%s",str) != EOF)
{
flag = 1;
len = strlen(str);
for(i =0; i< len/2; i++)
{
if(str[i] != str[len - i - 1])//通过指向首尾两个位置的指针相向移动进行比较,所对应的值不相同则不为回文。
{
flag = 0;
break;
}
}
if(flag)
printf("yes\n");
else
printf("no\n");
}
return 0;
} /* ----- End of main() ----- */