1.读程序,写出你的分析步骤,得出结果。
三道典型C语言题(4)


2.阅读一下程序,找出错误并更改。PS:以下代码是把一个字符串倒序,如“abcd”倒序后变为“dcba”” 

<所有头文件都已包含> 
main()    
{    
char*src=”hello,world”;    
char* dest=NULL;    
int len=sizeof(src);    
dest=(char*)malloc(len);       
char* s=src[len];   
while(len–!=0)    
dest++=s–;    
printf(“%s”,dest);    
return 0;    
}
三道典型C语言题(4)


3、编写一个函数,作用是把一个char组成的字符串循环右移n个。比如原来是“abcdefghi”如果n=2,移位后应该是“hiabcdefg”


//pStr是指向以”结尾的字符串的指针 
//steps是要求移动的n

void LoopMove ( char * pStr, int steps ) 

 int shift;
  int len=strlen(a);
  char b[MAX_LEN]={0};
  
  for(int i=0;i<len;i++)
  {
    shift=(i+steps)%len;
b[shift]=a[i];
  }
  printf("%s",b);
}


相关文章: