这是我的小片段,给我带来麻烦:
int main(int argc, char** argv) {
char string[75] = {0时 时;
char *pChar;
int count = 0;
printf("String: ");
fgets(string, sizeof string, stdin);
printf("Numero parole: %d
", countWords(string, strlen(string)));
// Suddivido la stringa nelle varie parole
pChar = strtok(string, " ");
while(pChar){
if(isWord(pChar, strlen(pChar))){
count += strlen(pChar);
时 时
pChar = strtok(NULL, " ");
时 时
printf("Lettere totali: %d
", count);
return (EXIT_SUCCESS);
时 时
问题在于没有指定值来计算变量。 我知道有问题,但我还是不知道什么是错的。
谢谢你的帮助
P.S. I 正在学习 C, 所以这可能是个愚蠢的问题。
< em> P. P. S. 按此请求设置为 word 函数 : em>
// Controlla se è una parola
int isWord(char string[], int length){
int i = 0; // Contatore
int countAlpha = 0; // Se il carattere è alfabetico. Non vengono
// contate le parole che contengono numeri
// Inizio scorrendo tutta la stringa tranne l ultimo carattere che è un
// terminatore di stringa
for(i; i < length - 1; i++){
// Se il carattere è alfabetico allora aumento il contatore isAlpha
if(isalpha(string[i])){
countAlpha++;
// Altrimenti il carattere non è una lettera
时 时 else {
countAlpha = 0;
时 时
时 时
if(countAlpha == i){
return 0;
时 时 else {
return 1;
时 时
时 时