打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【笔试】字符串常见笔试题

1 将字符串转化为整数。

long stringToInt(char *s){         long result=0;         for(int i=0;s[i]!='\0';i++)         {                    if(int(s[i])<48||int(s[i])>57)                      {//除去非数字                                      continue;                       }                     result=result*10+(s[i]-'0');          }         return result;}

2将整数转化为字符串。(考虑正负号的问题)

void itoa (int n,char s[]){     int i,j,sign;     if((sign=n)<0) 记录符号=""  =""  ="" n="-n;//使n成为正数"  =""  i="0;"  =""  do{=""  =""  =""  =""  ="" s[i++]="n+’0’;//取下一个数字"  =""  }while="" ((n/="10)">0);//删除该数字      if(sign<0)  =""  =""  =""  =""  ="" s[i++]="’-’;"  =""  =""  ="" s[i]="’\0’;"  =""  ="" for(j="i;j">=0;j--)//生成的数字是逆序的,所以要逆序输出       printf('%c',s[j]);}

3 实现字符串拷贝函数strcpy。(程序的完整性)

char * strcpy(char * strDest,const char * strSrc){if ((strDest==NULL)||(strSrc==NULL)) throw 'Invalid argument(s)'; char * strDestCopy=strDest; while ((*strDest++=*strSrc++)!='\0'); return strDestCopy;}

4 编程实现memcpy函数。(以字节为单位的拷贝)

void* mymemcpy(void* dest, void* source, size_t count){    char *ret = (char *)dest;    char *dest_t = ret;    char *source_t = (char *)source;    while (count--)    {         *dest_t++ = *source_t++;    }    return ret;}

5 编程实现memmove函数。

void* memmove(void* dest, void* source, size_t count)(考虑了指针地址重合的情况)   {       void* ret = dest;      if (dest <= source="" ||="" dest="">= (source + count))       {          //Non-Overlapping Buffers         //copy from lower addresses to higher addresses         while (count --)               *dest++ = *source++;     }     else     {        //Overlapping Buffers       //copy from higher addresses to lower addresses       dest += count - 1;       source += count - 1;       while (count--)                *dest-- = *source--;l     }      return ret;   }

同memcpy一样,在写的实际过程中我们始终以字节为单位进行相关的拷贝。

6写一个函数,目的是把char组成的字符串循环右移n位。比如,“abcde”,移动两位变为“deabc”.

编程实现:提示 strcpy函数,或者memcpy函数。

全文见原文。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
strcpy和memcpy的区别
NO.37 ----C语言库函数中字符串相关函数的模拟实现
C语言中memcopy函数功能及用法 .
公用子函数
C语言字符串操作总结大全(超详细)
memcopy和memmove 区别(另strcpy(), strncpy()和memset()) 收藏
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服