C 實驗十三 指標與字串

2021-10-11 18:18:12 字數 1125 閱讀 2108

1.找出最長的字串。輸入5個字串,輸出其中最長的字串。輸入字串呼叫函式scanf(「%d」,sx);輸入輸出示例:

輸入:input 5 strings: wang zhang li jin qian

輸出:the longest is: zhang

#include

#include

intmain()

}printf

("the longest is:");

printf

("%s"

,sx[t]);

return0;

}

2.要求定義並呼叫函式delchar(str,c),它的功能是將字串str**現的所有c字元刪除,函式形參str的型別是字元指標,形參c的型別是char,函式型別是void。

輸入輸出示例(括號內為說明) 如下:

#include

void delchar (

char

*str,

char c)}*

(str+j)

='\0'

;printf

("result:%s"

,str);}

intmain()

3.輸入乙個字串t和乙個正整數m,將字串t中從第m個字元開始的全部字元複製到字串s中,在輸出字串s

要求並定義函式strmcpy(s,t,m),它的功能是將字串t中從第m個字元開始的全部字元複製到字串s中,函式形參s和t的型別是字元指標,形參m的型別是int,函式型別是void。

#include

void

strmcpy

(char

*s,char

*t,int m)}*

(s+k)

='\0'

;printf

("%s"

,s);

}int

main()

C 字串指標與字串陣列

在做面試100題中第21題時,發現char astr abcdefghijk 0 和char astr 有點區別,以前一直以為是一樣的,但是在該程式中採用字串指標執行一直出錯。後來在網上查查,果然發現大大的不同。分析 當你需要修改字串時,採用指標指向該字串編譯通過但是執行出錯,而採用字串陣列時不會出...

C 字串指標與字元陣列

visual studio 2012 系統分配時儲存位置不一樣 字串指標在初始化時儲存在靜態區是常量,初始化後不能修改 字元陣列 是存放在棧中的,值是可以修改的 include stdafx.h include include include include include include char...

字元指標與字串

例項1 include using namespace std int main 執行結果 error 例項2 include using namespace std int main 執行結果 helloworld例項3 include using namespace std int main 執...