주의점
-
start, end 방식으로 잡아낸다.
-
start를 만드는 부분 중간에
str[i] == ‘\0’인지 검사하는 부분을 넣어준다.cwhile (str[i] == ' ' || str[i] == '\t') i++; if (str[i] == '\0') break ; start = i;
문제
Assignment name : last_word
Expected files : last_word.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that takes a string and displays its last word followed by a \n.
A word is a section of string delimited by spaces/tabs or by the start/end of
the string.
If the number of parameters is not 1, or there are no words, display a newline.
Example:
$> ./last_word "FOR PONY" | cat -e
PONY$
$> ./last_word "this ... is sparta, then again, maybe not" | cat -e
not$
$> ./last_word " " | cat -e
$
$> ./last_word "a" "b" | cat -e
$
$> ./last_word " lorem,ipsum " | cat -e
lorem,ipsum$
$>