Google

«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
BLOG Total Visitors
Today Hit, Yesterday Hit
BLOG main image


visitor stats
'포인터변수'에 해당되는 글 1건
[Schizo!, 2007. 12. 4. 23:11, study/programming]
이번 과제는 포인터를 사용하여 스트링에서 부분적으로 일치하는 스트링을 찾는 것이다.  스트링과 관련된 함수로 strcpy, strcmp, strcat, strlen, strlwr, strupr, strchr, strstr, strdup, strspn,  등 많은 함수들을 제공한다.  이들 함수들에 대하여 숙지하기 바라며 이번 과제는 strstr을 구현하는 과제이다.  문서에 보면 이 함수는 다음과 같이 선언된다.
char *strstr(const char *string, const char *strCharSet);
여기서 const는 함수의 정의 내에서 그 매개변수는 변경시킬 수 없음을 의미한다.  이 함수는 string에서 strCharSet를 찾아서 처음으로 나타나는 스트링의 위치를 return 하는데 찾을 수 없으면 NULL을 return한다.   이러한 기능을 가지는 함수
myStrstr(const char *string, const char *strCharSet);
를 구현하라.  더 필요한 것이 있으면 strstr를 참고하기 바랍니다.
예를 들어 string이 “abcdefghijklmnopqrstuvwxyz”일 경우 찾는 문자열을 입력받아 실행되는 과정은 다음과 같다.
? bced
No ...
? bcde
bcdefghijklmnopqrstuvwxyz
? hijkl
hijklmnopqrstuvwxyz
? stuv
stuvwxyz
? xyz
xyz
? opqr
opqrstuvwxyz
?
Bye ...
Press any key to continue


[프로그램]
#include <stdio.h>

#defineN50

void main()
{
char strMsg[] = "abcdefghijklmnopqrstuvwxyz";
char strMyStr[N];

while (1) {
printf("? ");
gets(strMyStr);
if (*strMyStr == NULL)
break;
char *myStrStr(const char *string, const char *strCharSet);
char *strFound = myStrStr(strMsg, strMyStr);
if (strFound == NULL)
printf("No ...\n");
else
printf("%s\n", strFound);
}
printf("Bye ...\n");
}

char *myStrStr(const char *string, const char *strCharSet)
{
// ???
// ???
}

'study > programming' 카테고리의 다른 글

포인터  (2) 2007.12.07
포인터  (0) 2007.12.07
불 대수의 법칙..  (0) 2007.11.26
배열 c  (3) 2007.11.26
배열 오름차순  (0) 2007.11.21


본인의 아이피 주소 확인과 위치 추적
*1