Contents

조회 수 9486 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
C로 프로그래밍 하다보면 문자열 때문에 문제가 많아지죠^^
문자열 제어.. 특히 문자열 토큰에 관해서는 힘든 부분이 많죠^^

아래 문자열 토큰에 관한 함수 하나 소개합니다.

void word_tok(char *dest, char *str, char key);

- dest 잘라진 문자열이 복사될 포인터
- str   원본 문자열
- key  기준이 되믄 문자 하나

str에서 key를 만나기 전까지의 문자열을 dest에 복사하고
str문자열에서 key전까지의 문자열은 제거 됩니다(공백도 제거)

아직 에러 검출에 관한 내용이 없어서 리턴 값은 없구여..
추가하면 다시 여기에 올리겠습니다^^

함수 예제)
void word_tok(char *dest, char *str, char key){
    char *word;
    int len=0, i;

    while(str[len]!=key && str[len]!='' && str[len]!='n') len++;
    word = (char *) malloc( sizeof(char)*(len +1) );

    for(i=0; i<len; i++) word[i] = str[i];
    word[i] = '';

    strcpy(dest, word);
    free(word);

    while(str[len]==' ') len++;
    strcpy(str, str+len);
}


?

  1. [c] 소수 구하기 #1 (한정된 숫자 내에 있는 소수 걸러내기)

    Date2003.04.23 CategoryDevelop Byhooni Views9102
    Read More
  2. [c] 셀프 넘버(Self Number) 구하기

    Date2016.09.09 CategoryDevelop Byhooni Views3823
    Read More
  3. [c] 서비스 거부 공격(DoS;Denial of Service) 간단 소스.. ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views7748
    Read More
  4. [c] 분수계산 함수^^

    Date2003.04.23 CategoryDevelop Byhooni Views11370
    Read More
  5. [c] 베지어 곡선(Bézier curve) 알고리즘

    Date2013.04.23 CategoryDevelop Byhooni Views9415
    Read More
  6. [c] 베이지언(Bayesian) 패턴인식 과제 ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views8016
    Read More
  7. [c] 반올림 함수!! ㅋㅋ

    Date2003.04.23 CategoryDevelop Byhooni Views9457
    Read More
  8. [c] 바로 보고 정리할 것.. ㅋㄷㅋㄷ

    Date2013.04.23 CategoryDevelop Byhooni Views8044
    Read More
  9. [c] 민수형 소스(도메인소켓포함)

    Date2013.04.23 CategoryDevelop Byhooni Views7490
    Read More
  10. [c] 민수형 libipq 샘플 소스 ㅋㅋ

    Date2003.04.23 CategoryDevelop Byhooni Views15100
    Read More
  11. [c] 문자열 컨트롤 함수로 만든 프로그램들..

    Date2003.04.23 CategoryDevelop Byhooni Views8115
    Read More
  12. [c] 문자열 치환해주는 str_replace() 함수

    Date2013.04.23 CategoryDevelop Byhooni Views8187
    Read More
Board Pagination Prev 1 ... 42 43 44 45 46 47 48 49 50 51 ... 71 Next
/ 71