1. c語言問題關於字元串相減
因為cost與cos的前面是相同的,只有最後一個t不同.即當i=3時,由於str2[3]='\0'所以退出for循環.str1[3]='t',所以str1[3]
不等於str2[3],所以執行 else
printf('%d\n',abs(str1[i]-str[i]));
str1[3]-str2[3]='t'-'\0'='t'
abs是求絕對值.返回整型值,'t'的asc碼是116,所以abs('t')的結果是116
2. c語言中字元數組相減問題,字元數組名想減是什麼意思求幫忙解答!
數組名相減,求的是地址之間的距離。
數組名表示數組的首地址。
x[7] 表示x數組的第8個 元素,即字元串結束符。
3. C語言中字元串相減是什麼意思
(1) C語言中沒有 字元串相減 運算。
(2) C語言中 有 單個字元 相減 運算。
例如,把字元串"1234"里的各個數字字元轉成整型,存入整型數組:
int i,x[4];
char str[]="1234";
for (i=0;i<4;i++) x[i] = str[i] - '0';
例如, 把字元串中字母,小寫變大寫:
char str[]="aBcxYz";
int i;
for (i=0;i<strlen(str);i++)
if (str[i] >='a' && str[i] <='z') str[i] = str[i] -'a' + 'A';
(3) 字元串大小比較 用 strcmp() 或 strncmp() 函數
例如:
if (strcmp(a,b) == 0) printf(" string a and b are the same\n");
if (strcmp(a,b) > 0) printf(" string a is bigger than b\n");
4. c語言 大數相減A-B problem
while(i>=0){
result=addnum1[i--]-'0'+carry;
carry=result/10;
total[k++]=result%10+'0';
}
while(j>=0){
result=addnum2[j--]-'0'+carry;
carry=result/10;
total[k++]=result%10+'0';
}
if(carry)total[k++]=carry+'0';
total[k]='