| 원하는 단어 앞까지만 출력하기. |
Tech - https://ohyung.net/588 (YMD: 09/02/20 23:38)
광게에 누가 올려놨길래.. 슬금슬금 코딩해본것...

Code Type : C
#include < stdio.h>
#include < string.h>

int main(void)
{
   char a[80];
   char b[5] = "stop";
   int i;

   fgets(a, 79, stdin);

   for(i = 0; i < strstr(a, b) - a; i++)
    {
        printf("%c", a[i]);
    }

}

stop이라는 단어가 들어오지 않을경우..에는 for문이 돌지 않기 때문에 관련이 없지 않을까?

그래도... 혹시나 싶어...

Code Type : C
#include < stdio.h>
#include < string.h>

int main(void)
{
   char a[80];
   char b[5] = "stop";
   int i, j;

   fgets(a, 79, stdin);
   j = strstr(a, b);
   if (j)
   {
      for (i = 0; i < j - a; i++)
      {
        printf("%c", a[i]);
      }
   }
   else
   {
      printf("stop이라는 단어가 없습니다.\n");
   }

   return 0;
}


그냥 심심해서 해본 코딩 -.ㅡ;
태그 : ,
| 이 포스트에 대한 이용규약 |
Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시 2.0 라이센스 에 따라 이용하실 수 있습니다.
This work is licensed under a Creative Commons Attribution 2.0 Korea LicenseLink in a new window.

| 이 글과 태그로 연관된 글 |

| 트랙백 |
트랙백 주소 :: https://www.ohyung.net/rserver.php?mode=tb&sl=588