Demo entry 6647991

gcc

   

Submitted by anonymous on Oct 22, 2017 at 14:21
Language: C. Code size: 1.1 kB.

// 인자로 받은 옵션을 확인
        while (argv[i])
        {
                // ls 옵션에 해당되는 내용이 있으면 플래그 설정
                if (argv[i][0] == '-')
                {
                        for(j = 1; j < strlen(argv[i]); j++)
                        {
                                // 옵션이 중복체크 되지 않도록 함
                                switch (argv[i][j])
                                {
                                case 'L':
                                        if((ls_flag & 0x01) == 0)
                                                ls_flag |= 0x1;
                                        break;
                                case 'S':
                                        if((ls_flag & 0x02) == 0)
                                                ls_flag |= 0x2;
                                        break;
                                default:
                                        printf("usage : ls [-LS] [directory_name]\n");
                                        exit(1);
                                }
                        }
                }

                i++;
        }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).