重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
可以參考下面的代碼:
成都創新互聯作為成都網站建設公司,專注網站建設、網站設計,有關企業網站設計方案、改版、費用等問題,行業涉及成都會所設計等多個領域,已為上千家企業服務,得到了客戶的尊重與認可。
#include stdio.h
#include stdlib.h
void movefour(char *str)
{
int i,j;
char t;
for(i=0;i4;i++)
{
t=str[strlen(str)-1];
for(j=strlen(str)-1;j0;j--)
str[j]=str[j-1];
str[0]=t;? ? ? ? ? ?
}
}
擴展資料:
C語言strcat()函數:字符串連接(拼接)
C語言isupper()函數:判斷一個字符是否是大寫字母
C語言isspace()函數:判斷一個字符是否是空白符
C語言isprint()函數:判斷一個字符是否是可打印字符
C語言islower()函數:判斷一個字符是否是小寫字母
C語言ldexp()函數:返回x乘以2的exponent次方(次冪)的值
C語言isalnum()函數:判斷一個字符是否是字母或者數字
參考資料來源:百度百科-C語言函數
//函數,輸入字符串,返回字符串前三字母。
publicfunctiongetStoreName($str){
$one=mb_substr($str,0,1,'utf-8');
$two=mb_substr($str,1,2,'utf-8');
$three=mb_substr($str,2,3,'utf-8');
if(preg_match('/^[\x7f-\xff]+$/',$one)){
$one=getFirstCharter($one);
}
if(preg_match('/^[\x7f-\xff]+$/',$two)){
$two=getFirstCharter($two);
}
if(preg_match('/^[\x7f-\xff]+$/',$three)){
$three=getFirstCharter($three);
}
return??$one.$two.$three;
}
擴展資料:
寫一個函數,將一個字符串中的元音字母復制到另一字符串,然后輸出。
代碼塊:
方法1:
#includestdio.h
#includestring.h
charycopy(charx[],chary[]);??????//定義復制函數。
main()
{
chara[20],b[20];
gets(a);???????????????//輸入字符串。
b[20]=ycopy(a,b);??????????//調用復制函數。
puts(b);???????????????//輸出復制后的字符串。
return0;
}
//元音復制函數。
charycopy(charx[],chary[])
{
intm,i,j;
m=strlen(x);
for(i=0,j=0;im;i++){
if(x[i]=='a'||x[i]=='A')
y[j++]=x[i];
elseif(x[i]=='e'||x[i]=='E')
y[j++]=x[i];
elseif(x[i]=='i'||x[i]=='I')
y[j++]=x[i];
elseif(x[i]=='o'||x[i]=='O')
y[j++]=x[i];
elseif(x[i]=='u'||x[i]=='U')
y[j++]=x[i];
}
y[j]='\0';
returny[j];
}
方法2:
#includestdio.h
#includestring.h
voidinput(charst[]);??????????????//定義輸入函數。
voidoutput(charst[]);??????????????//定義輸出函數。
voidletter(charx[],chary[]);?????????//定義元音復制函數。
intmain()
{
chars1[20],s2[10];
input(s1);??????????????????//調用輸入函數。
letter(s1,s2);????????????????//調用元音復制函數。
output(s2);??????????????????//調用輸出函數。
return0;
}
//輸入函數。
voidinput(charst[])
{
printf("Pleaseenterstring:");
gets(st);
}
//元音復制函數。
voidletter(charx[],chary[])
{
intn=strlen(x);
for(inti=0,j=0;in;
(x[i]=='a'||x[i]=='e'||x[i]=='i'||x[i]=='o'||x[i]=='u'||x[i]=='A'||x[i]=='E'||x[i]=='I'||x[i]=='O'||x[i]=='U')?y[j++]=x[i++]:i++);
y[j]='\0';
}
//輸出函數。
voidoutput(charst[])
{
printf("Thefinalstring:%s\n",st);
}
如圖,源代碼在網頁端發
你的思路不好,我改寫了。
#include?stdio.h
#include?string.h
#define?MAXS?100
void?Shift(?char?s[]?);
void?GetString(?char?s[]?);?/*?實現細節在此不表?*/
int?main()
{
char?s[MAXS];
GetString(s);
Shift(s); //交換
printf("%s\n",?s);
return?0;?
}
void?GetString(?char?s[]?){//不寫這個無法驗證
scanf("%s",s);
}
void?Shift(?char?s[]?){
char?a[3];
int?i,j;
for(i=0;?i3?;i++){
a[i]=s[i];?//將前3個字母存到a
}
//此時i已經=3
for(;?s[i]!='\0'?;i++){
s[i-3]=s[i];
} //i從3開始?直到遇到結束符'\0',往前3格賦值
i-=3; //最后i要退回3格
for(j=0;?j3?;j++){
s[i++]=a[j];
} //將最后3個字母賦值為之前存到a的
}