[問題] 計算字串長度
我所使用的程式軟體是visual c++200
這個部分我沒有學到額外的函式庫
這題是我想了很久還想不出來的題目
輸入一個字串,計算長度,使用第一個迴圈走訪每個字元
一個變數用來累加走訪的次數
迴圈進入條件沒有遇到結束字元
while (str[i])='\0'
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
char word[1000];
int i,len;
printf("請輸入一個字串 :");
scanf("%s",word);
len = strlen(word);
printf("此字串長度為 :%d\n",len);
printf("其反向字串為 :");
for(i=len-1;i>=0;i--){
printf("%c",word[i]);
}
printf("\n");
system("PAUSE");
return 0;
}
我真的看不懂這題,上面的程式是我一個親戚教我的,可是我覺得有點怪
因為跟我的題目不符合
無法執行
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
char word[1000];
int i,len;
printf("請輸入一個字串 :");
scanf("%s",word);
len = strlen(word);
printf("此字串長度為 :%d\n",len);
printf("其反向字串為 :");
for(i=len-1;i>=0;i--){
printf("%c",word[i]);
}
printf("\n");
system("PAUSE");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.69.42.180
→
12/06 11:50, , 1F
12/06 11:50, 1F