我提出一个问题,争论不一。 C. Im 脂重 在我的任务中,需要具体说明未申报参数中的类型。 这似乎没有任何理由这样做,因为一米仅使用护卫,但需要使用“带”;stdarg.h>。 该职能可以打印文字,具体文字重复三倍。 因此,当我尝试这一法典时:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
void repeatingLetter(char* sentence, char letter)
{
char* word = strtok(sentence, " ");
while (word != NULL) {
int count = 0;
int len = strlen(word);
for (int i = 0; i < len; i++) {
if (word[i] == letter) {
count++;
}
}
if (count >= 3) {
printf("%s
", word);
}
word = strtok(NULL, " ");
}
}
void findWords(int numSentences, ...)
{
va_list args;
va_start(args, numSentences);
char letter;
printf("Enter a letter to check: ");
scanf("%c", &letter);
for (int i = 0; i < numSentences; i++)
{
char* sentence = va_arg(args, char*);
printf("Words in %s with %c repeated 3 or more times:
", sentence, letter);
repeatingLetter(sentence, letter);
printf("
");
}
va_end(args);
}
int main()
{
int numSentences;
printf("Enter a number of sentences: ");
scanf("%d", &numSentences);
getchar();
char** sentences = (char**)malloc(numSentences * sizeof(char*));
for (int i = 0; i < numSentences; i++)
{
sentences[i] = (char*)malloc(100 * sizeof(char));
printf("Enter a sentences %d: ", i + 1);
fgets(sentences[i], 100, stdin);
sentences[i][strcspn(sentences[i], "
")] = ;
}
findWords(numSentences, sentences);
for (int i = 0; i < numSentences; i++)
{
free(sentences[i]);
}
free(sentences);
return 0;
}
I:
Enter a number of sentences: 3
Enter a sentences 1: Hello world
Enter a sentences 2: oooooops
Enter a sentences 3: gdsgdgdg
Enter a letter to check: o
Words in ╨Ъ.┌c with o repeated 3 or more times:
Words in ╨Ъ.┌c with o repeated 3 or more times:
Words in o
gdgdg
d
with o repeated 3 or more times:
我不理解问题是什么。 您能否帮助我?
我曾试图以愤怒和浮动的方式这样做。 不存在任何问题,但我无法理解在扼杀方面有哪些错误。