【发布时间】:2016-06-02 09:12:18
【问题描述】:
我有 char* 指针并试图计算每个单词的长度。但我在调试器中没有得到任何结果(只是空白)。无论我改变什么,我都没有得到任何结果。代码:
void wordsLen(char* text, int* words, int n)
{
int i, count = 0, s = 0;
//words[countWords(text)]; // not important
for (i=0; i < n; i++)
{
if (text[i] != ' ')
{
count++;
}
else
{
printf("%d",count);
}
printf("%d",count);//if I add this it types the count from 1 to the end
}
}
我尝试插入这个数组:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define N 100
void main()
{
char t[] = "hello my name is.";
int cum[N];
wordsLen(t, cum, strlen(t));
getch();
}
由于没有得到任何结果,我想知道为什么,计算单词长度的代码有什么问题吗?比如计算单词的长度有好处吗?还是我需要改变一些东西。
【问题讨论】:
-
wordsLen是否有值? -
另外,
words[countWords(text)];是什么? -
C 还是 C++?有不同的语言
-
countwords(text) 返回 text* 和 c++ 中的单词数,如有错误请见谅。
-
您发布了由于多种原因无法编译的代码,然后在人们试图提供帮助时开始对其进行修改。我不赞成,vtc 是“不清楚”:(