超簡單的C語言問題,怎麼定義字串?

2025-03-03 19:00:13 字數 1983 閱讀 9118

1樓:高金山

把宣告中的返回值char去掉就行了,如下:

enmonth(int m);

#include

void main()/輸入月改消消份,輸出相應的英文名稱int month;

scanf("%d",&month);

if(month>=1&&month<=12)enmonth(month);

enmonth(int m)

char *months[12];

months[0]="january";

months[1]="february";

months[2]="march"橋局;

months[3]="april";

months[4]="may";

months[5]="june";

months[6]="july";

months[7]="august";

months[8]="september";

months[9]="octorber";

months[10]="november"核知;

months[11]="december";

printf("%s",months[m-1]);

2樓:

改 指標函歲族數:

char * enmonth(int m) {函式里 加return ,也不必在子程式乎亂弊裡列印。

char * enmonth(int m);

void main()

int month;

scanf("%d"陪攔,&month);

if(month>=1&&month<=12)printf("%s", enmonth(month));

char * enmonth(int m)char *months[12];

months[0]="january";

months[1]="february";

months[2]="march";

months[3]="april";

months[4]="may";

months[5]="june";

months[6]="july";

months[7]="august";

months[8]="september";

months[9]="octorber";

months[10]="november";

months[11]="december";

return months[m-1];

3樓:臺融封含景

改。指標函式:

charenmonth(intm)

函式首前裡。

加悄芹猜return

也不必在啟型子程式裡列印。

charenmonth(int

m);void

main()

intmonth;

scanf("%d",&month);

if(month>=1&&month<=12)printf("%s",enmonth(month));

charenmonth(int

m)char

months[12];

months[0]="january";

months[1]="february";

months[2]="march";

months[3]="april";

months[4]="may";

months[5]="june";

months[6]="july";

months[7]="august";

months[8]="september";

months[9]="octorber";

months[10]="november";

months[11]="december";

return

months[m-1];

c語言中怎麼樣定義字串變數c語言中怎麼樣定義一個字串變數

c語言沒有字串型別,所以沒辦法進行定義字串變數。但是可以用字元陣列來處理字串。這定義了一個字元陣列,名為a 例 char a hello 也可以用來定義一個指標變數 定義了一個指標變數,名為p 例 char p hello 接觸c語言幾天。查了一些資料是這樣理解的,有不對的地方一起學習啦。一維的情況...

c語言基礎問題如何合併字元,C語言怎麼合併兩個字串

以下 可以達到你的要求 include int main printf num d n num table 0 a table 1 b table 2 c for i 0 i 3 i str i 0 printf str s n str return 0 include include includ...

簡單的c語言問題,一個簡單的c語言問題

你其實是想做字串逆序輸出對吧,char dest char malloc len 1 這句是給dest申請空間 char a src len 1 把src陣列的最後一個地址賦值給a char b dest 把dest的第一個的地址賦值給b int j 用j計數迴圈 j len 迴圈len次 whil...