[질문]간단한C언어 if랑 goto문만으로 다시쓸수잇을까요?
글쓴이: zzwing / 작성시간: 일, 2004/10/24 - 4:19오후
스트링 함수인데요 이것을 if goto문만으로 다시해볼려구하는데 잘 모르것네요
C잘하시는 분이 좀 해주셨음 좋겠어요 복잡하더라도 보고 열심히 공부할게요
그리구 이왕이면 직접 고쳐서 올려주심 좋겠습니다. 설명만으로는 잘 몰라서요 ^^;
#include <stdio.h>
my_strlen(char *s)
{
char *p = s;
while(*p)
p++;
return(p-s);
}
main()
{
char p[10] = "Kim";
printf("length of \"kim\" is %d\n",my_strlen(p));
}
#include <stdio.h>
void my_strcpy(char *s,char *t)
{
while((*s++ = *t++));
}
main()
{
char *x = "Kim";
char y[10];
my_strcpy(y,x);
printf("%s %s\n",x,y);
}
#include <stdio.h>
int my_strcmp(char *s,char *t)
{
for( ; *s == *t; s++, t++)
if (*s == '\0')
return(0);
return(*s - *t);
}
main()
{
char *p = "Kwon";
char *q = "Kim";
int cmp = my_strcmp(p,q);
if (cmp == 0) {
printf("Kwon equals Kim.\n");
} else if (cmp > 0) {
printf("Kwon is greater than Kim.\n");
} else if (cmp < 0) {
printf("Kwon is less than Kim.\n");
}
#include <stdio.h>
#include <string.h>
void my_strcat(char s[],char t[])
{
int i,j;
i = j = 0;
while(s[i] != '\0')
i++;
while((s[i++] = t[j++]) != '\0')
;
}
main()
{
char *p = "Taegyun";
char q[20];
strcpy(q,"Kim");
my_strcat(q,p);
printf("%s %s\n",p,q);
}
Forums:


while() -->loop:......if(
while()
-->
loop:
...
...
if(조건)
goto loop_out;
else
goto loop;
loop_out:
...
...
정도가 아닐까요.. while문만 goto문으로 대치시키면 되는거니까요..
물론 문법이 맞는진 모릅니다 goto문을 한번도 안써봤거든요 ㅎㅎ 그냥 어셈에서 jmp와 비슷한 사용법정도로 파악만 하고있습니다 ;;
..
my_strlen(char *s) { char *p = s; loop: if(*p) { p++; goto loop; } return (p-s); }이렇게 하면 맞을거라 생각합니다.
VENI VIDI VICI
댓글 달기