c語言輸入字串,將該字串中從第m個字元開始的全部字元複製到另字串

2021-07-30 06:14:50 字數 5158 閱讀 6143

1樓:大野瘦子

這樣:#include

#include

int main ()

void copystr(char *,char *,int);

int m;

char str1[20],str2[20];

printf("input string:");

gets(str1);

printf("which character that begin to copy?");

scanf("%d",&m);

if(strlen(str1) < m)

printf("input error!");

else

copystr(str1,str2,m);

printf("result:%s\n",str2);

return 0;

void copystr(char *p1,char *p2,int m)

int n;

n = 0;

while(n < m - 1)

n++;

p1++;

while(*p1 != '\0')

*p2 = *p1;

p1++;

p2++;

*p2 = '\0';

注意事項

/*輸入一個字串,將該字串中從第m個字元

開始的全部字元複製成另一個字串。m由使用者

輸入,小於字串的長度。*/

#include

#include

void mcopy(char array1,char array2,int m)

int i,j;

for(i=m-1,j=0;array2[j]!=0;i++,j++)

array1[i]=array2[j];

array1[i]=0;

int main()

char array1[20],array2[10];

int m;

printf("give array1:");

gets(array1);

printf("give array2:");

gets(array2);

printf("give m:");

scanf("%d",&m);

mcopy(array1,array2,m);

printf("after changed:");

puts(array1);

return 0;

2樓:會飛的小兔子

#include

#include

intcopy(char*p1,char*p2,intm);

intmain()

charstr1[40],str2[40];

printf("輸入第一個字串:\n");

gets(str1);

intm;

printf("輸入第m個字元開始:\n");

scanf("%d",&m);

if(strlen(str1)printf("錯誤");

else

copy(str1,str2,m);

printf("%s",str2);

return0;

intcopy(char*p1,char*p2,intm)

intn;

n=0;

while(nn++;

p1++;

while(*p1!='\0')

*p2=*p1;

p1++;

p2++;

擴充套件資料

c語言字元指標字串複製

#include

voidcopy(chardststr,charsrcstr);

intmain()

chara[100],b[100];

printf("pleaseenterastring:");

gets(a);//輸入字串,存放陣列a中

copy(b,a);//將字元陣列a中的字串複製到b中

printf("thecopyis:\n");

puts(b);//輸出複製後的字串b

return0;

voidcopy(char*dststr,char*srcstr)

while(*srcstr!='\0')//迴圈直到字元srcstr[i]是字串的結束標誌為止

*dststr=*srcstr;//複製當前指標所指向的字元

srcstr++;//使srcstr指向下一個字元

dststr++;//使dststr指向下一個儲存單元

*dststr='\0';//在字串dststr的末尾新增字元的結束標誌,避免複製的字串溢位

//或則函式copy()編寫成這樣

voidcopy(char*dststr,char*srcstr)

do*dststr=*srcstr;//複製當前指標所指向的字元

srcstr++;//使srcstr指向下一個字元

dststr++;//使dststr指向下一個儲存單元

}while(*srcstr!='\0');//迴圈直到字元srcstr[i]是字串的結束標誌為止

事實上,還可以如下更為簡潔的形式編寫函式copy():

voidcopy(char*dststr,char*srcstr)

while((*dststr++=*srcstr++)!='\0')//迴圈直到字元srcstr[i]是字串的結束標誌為止

3樓:匿名使用者

當然是一個字元了 你的函式的引數應該如下改#include

int m=3;int i;

int sort(char *p3,char *p4)}int main(int argc, char *argv);char b[10]=;

char *p1,*p2;

p1=&a[0];

p2=&b[0];

sort(p1,p2);

printf("%s",*p1);

return 0;}

4樓:

#include

int m=3;int i,j;

void sort(char st,char ss)}int _tmain(int argc, _tchar* argv)

;char b[10]=;

sort(a,b);

printf("%s",a);

return 0;}

編寫一個程式,將字串中的第m個字元開始的全部字元複製到另一個字串。 5

5樓:南瓜蘋果

**如下:

#include

#include

int copy(char *p1,char *p2,int m);

int main()

return 0;

}int copy(char *p1,char *p2,int m)while(*p1!='\0')

}擴充套件資料字串一般記為 s=“a1a2···an”(n>=0)。它是程式語言中表示文字的資料型別。在程式設計中,字串(string)為符號或數值的一個連續序列,如符號串(一串字元)或二進位制數字串(一串二進位制數字)。

通常以串的整體作為操作物件,如:在串中查詢某個子串、求取一個子串、在串的某個位置上插入一個子串以及刪除一個子串等。

兩個字串相等的充要條件是:長度相等,並且各個對應位置上的字元都相等。設p、q是兩個串,求q在p中首次出現的位置的運算叫做模式匹配。

串的兩種最基本的儲存方式是順序儲存方式和連結儲存方式。

6樓:聽不清啊

#include

void copystring(char *sourcestr, char *tagstr, int m)

int main ()

c語言取某個字元後的字串存到另一個字串

7樓:匿名使用者

思路:先遍歷字串,如果找到該字元後,把後面的所有字元複製到另一個字串。

例如:#include

#include

int main ()

ch2[j]='\0';

puts(ch2);

return 0;}/*

輸出:56789*/

8樓:

**如下。。。我測試過了。。。。

#include "stdio.h"

main()

for(i=0;j

result1[i] = '\0';

puts(result1);

for(i = 0; i

for(i=0;j

result2[i] = '\0';

puts(result2);

getch();

}希望對你有幫助。。。。仍有問題可以hi我。。。。。

9樓:千鋒教育

#include

#include//支援strlen()的應用#include//支援exit(1)

char *mcopy(char*s ,int m); //函式的定義

void main(void)

str2=mcopy(str1,m); //程式的呼叫for(int j=0;j

printf("字串第%d個元素是%c\n",m++,str2[j]); //字元的輸出

}char *mcopy(char*s ,int m)return array;}

10樓:手機使用者

#include

#include

void main()

11樓:匿名使用者

#include

void main()

執行如下:

[ 58.154.16.0 - 58.154.31.255]

跪求c語言字串處理函式,跪求 c語言字串 7個處理函式

1.字串連線函式 strcat 原型 char strcat char str1,const char str2 2.字串查詢函式 strchr 原型 char strchr const char str1,const char str2 3.字串比較函式 strcmp 原型 int strcmp ...

如何從字串中刪除最後字元,如何從字串中刪除最後一個字元

string.slice 0,1 可以用第二個引數負數表示要去除幾位 char s 100 fgets s,sizeof s fp 從fp指向的檔案中提出最多100個字元的一行字元。s strlen s 1 0 讓最後一個字元的ascii碼為0,即結束標誌。fputs s,fw 將s寫入fw指向的檔...

c語言問題將字串a複製到字串b中

1 首先需要建立一個新的檔案,輸入標頭檔案和主函式。2 接下來需要定義變數型別。3 設定完變數型別之後開始呼叫cpy函式。4 接下來需要定義一個函式,並定義變數型別。5 最後加一個字串結束符,並在主函式中輸出。6 編譯。執行,可以看到字串a複製到字串b中。將字串a複製到字串b中,簡單的方法是使用st...