阅读背景:

在C中设置一个空字节。

来源:互联网 
int length = strlen(input_str);
output_s = malloc((sizeof(char*) * totalSentences) + 1);
for (int i = 0; i < totalSentences; i++) {
  output_s[i] = malloc((sizeof(char) * sentences[i]) + 1);
}

free(sentences);

currentSentence = 0;
int currentCharacter = 0;
int firstChar = 1;
for (int i = 0; i < length; i++) {

  if (isalpha(*input_str) && (firstChar == 1)) {
    output_s[currentSentence][currentCharacter] = (char)toupper(*input_str);
    currentCharacter++;
    firstChar = 0;
  } else if (isalpha(*input_str)) {
    output_s[currentSentence][currentCharacter] = (char)tolower(*input_str);
    currentCharacter++;
  } else if (!isspace(*input_str) && !ispunct(*input_str)) {
    output_s[currentSentence][currentCharacter] = *input_str;
    currentCharacter++;
  }

  if (isspace(*input_str)) {
    firstChar = 1;
  }

  if (ispunct(*input_str)) {
    firstChar = 1;
    currentCharacter = 0;
    currentSentence++;
    input_str++;
    if (currentSentence == totalSentences) {
      break;
    }
    continue;
  }

  input_str++;
}

output_s[totalSentences] = NULL;
int length = strlen(input_str);
output_s = mall



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: