2016년 6월 8일 수요일

이것이 c언어다. 11장 가장 긴 문자열찾기

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    char chWord;

    int ntemp = 0;
    int nMax = 0;

    printf("enter the string : (EXIT : Ctrl+z)");
    chWord = getchar();
    while(chWord != -1)
    {
        chWord = getchar();

        if(chWord == '\n' )
        {
            if(ntemp > nMax)
            {
                nMax = ntemp;
                ntemp = 0;
            }
            else ntemp = 0;
        }
        ntemp++;
    }
    printf("longest voca's count : %d\n",nMax-1); // 널문자값으로 1씩  나오기 때문에 -1을 해줌.
    return 0;
}


댓글 없음:

댓글 쓰기