나는 char * 포인터를 가지고 각 단어의 길이를 계산하려고합니다. 하지만 디버거 (그냥 빈 공간)에서 어떤 결과를 얻고있다. 내가 바꿀지라도 나는 어떤 결과도 얻지 못한다. 코드 :C의 각 단어의 길이를 계산합니다
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();
}
어떤 결과를 얻고 있지 않다 것은, 내가 이유를 알고 싶습니다 때문에, 그리고 문제는 길이를 계산하기위한 코드가 단어들? like는 단어의 길이를 세는 것에 좋습니까? 아니면 무언가를 바꿔야합니까?
합니까을 '값을 얻을 wordsLen'을? – Marievi
또한 단어 [countWords (텍스트)];는 무엇입니까? – Marievi
C 또는 C++? 다른 언어가 있습니다 – Garf365