C
[C] 222 특정 문자가 시작되는 위치 찾기 strcspn
qkrwngus
2021. 2. 7. 15:19
Desc :
기능이 한없이 모자라지만..
068번에 말씀하신 아이디 검사 코드를 작성해보았습니다
혹시 제가 발견하지 못한 오류가 있는지요!!
Source Code :
#include <stdio.h>
#include <string.h>
void main()
{
char string[10] = { 0, };
char *find = "~!@#$%^&*()_+";
int index;
while (1)
{
printf("영문또는 숫자로 이루어진 아이디: ");
gets(string);
index = strcspn(string, find);
if (index == strlen(string))
{
printf("사용할 수 있는 아이디입니다.\n");
break;
}
else
{
printf("%d위치에서 포함될 수 없는 문자가 있습니다.\n\n", index + 1);
}
}
}
Result :