Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dic_cat_command 함수 #3

Open
am0c opened this issue Feb 15, 2011 · 0 comments
Open

dic_cat_command 함수 #3

am0c opened this issue Feb 15, 2011 · 0 comments

Comments

@am0c
Copy link

am0c commented Feb 15, 2011

  if (!strcmp (input_message, DIC_COMMAND_LIST) || !strcmp (input_message, DIC_COMMAND_HELP))
    {
      if (!strcmp (input_message, DIC_COMMAND_LIST))
        {
          return 1; //1 : list
        }
      else
        {
          return 2; // 2: help
        }
    }

이런식으로 되어 있는데

      if (strcmp (input_message, DIC_COMMAND_LIST))
        {
          return 1; //1 : list
        }
      else if (strcmp (input_message, DIC_COMMAND_HELP))
        {
          return 2; // 2: help
        }
      else if ()
..
      else if ()
..
      else if ()
..

이렇게 하는게 낫습니다.

그리고 1, 2, 3, 4, 5 와 같이 상수를 부여할 때에는
여기에 의미있는 기호를 할당할 수 있는 enum을 사용하는 것이 좋습니다.

그리고 dic_cat_command를 만들었다면, 이 함수를 활용하여
다른 부분의 코드에서는 strcmp를 하지 않고, dic_cat_command를 호출하여 상수 비교를 하는 쪽이 좋습니다.
이때 상수비교는 switch 문으로 대체할 수 있습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant