본문 바로가기

[C언어 무따기]단어개수 구하기

반응형
문장의 마지막에 NULL이 포함되어서 그런지 단어갯수 + 배열의 갯수가 된다.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  char* word[5];
  int i , j;
  int num;
  int cnt = 0;
  
  word[0= "This is Saturday";
  word[1= "Today is very hot";
  word[2= "I want to play with my girl friend.";
  word[3= "But I have to study";
  word[4= "I will study certinly";
  
  //                                           num = strlen(word[0]);//+word[1]+word[2]+word[3]+word[4]);
  
  printf ("문자열의 크기: %d\n" , strlen(word[0])); 
  
  for( i = 0; i < 5; i++)
  {
       for( j = 0; j < strlen(word[i]); j++)
       {
            while(*word[i]++ !=' ');
            cnt++;
       }
  }
  
  printf("단어의 갯수 %d", cnt);
  
   


      
  

  system("PAUSE");  
  return 0;
}

반응형
-->