18禁网站免费,成年人黄色视频网站,熟妇高潮一区二区在线播放,国产精品高潮呻吟AV

學(xué)習(xí)啦 > 學(xué)習(xí)英語 > 專業(yè)英語 > 計(jì)算機(jī)英語 > c語言strcmp的用法

c語言strcmp的用法

時(shí)間: 長(zhǎng)思709 分享

c語言strcmp的用法

  函數(shù) int stringcompare(char *source, char *target) 比較字符串 source 和 target,并根據(jù) source 是否小于、等于或大于 target 的結(jié)果分別返回負(fù)整數(shù)、0或者整數(shù)。該返回值是 source 和 target 由前后逐字符比較時(shí)遇到的第一個(gè)不相等字符處的字符的差值。下面小編就來為大家介紹下c語言strcmp的用法。
  #include <stdio.h>
  int stringcompare(char *source, char *target);
  int main()
  {
  char str_a[] = "Welcome to www.nowamagic.net";
  char str_b[] = "Welcome to www.nowamagic.net";
  int wait, result;
  result = stringcompare(str_b, str_a);
  printf("After Function Call: \n");
  printf("result is '%d' \n", result);
  scanf("%d", &wait);
  }
  /* 根據(jù) source 按照字典順序小于、等于或大于 target 的結(jié)果分別返回負(fù)整數(shù)、0或者整數(shù) */
  int stringcompare(char *source, char *target)
  {
  int i;
  for(i = 0; source[i] == target[i]; i++)
  {
  if (source[i] == '\0')
  return 0;
  return source[i] - target[i];
  }
  }
  下面再用指針實(shí)現(xiàn):
  int stringcompare(char *source, char *target)
  {
  for ( ; *source == *target; source++, target++)
  if (*source == '\0')
  return 0;
  return *source - *target;
  }
  關(guān)于指針自增與自減有下面一種用法:
  /* 將val壓入棧 */
  *p++ = val;
  /* 將棧頂元素彈出到val中 */
  val = *--p;
  這兩個(gè)表達(dá)式是進(jìn)棧和出棧的標(biāo)準(zhǔn)用法。
514777