C언어 복습 (문자열 복사 함수)
내장형 하드웨어/C언어 / 2011. 6. 16. 17:56
#include<stdio.h>
#include<string.h>
int main()
{
const char *p;
const char *Text = "This is a ATMega";
char T[4][7];
p=Text;
strncpy(T[0],p,4); // 문자를 복사하는 함수
p=p+5; // 다음에 출력할 문자만큼 이동한다.
T[0][4]=0; // Null 문자 입력
strncpy(T[1],p,2);
p=p+3;
T[1][2]=0;
strncpy(T[2],p,1);
p=p+2;
T[2][1]=0;
strncpy(T[3],p,6);
p=p+7;
T[3][6]=0;
printf("T[0] = [%s]\n",T[0]); // This만 출력
printf("T[1] = [%s]\n",T[1]); // is만 출력
printf("T[2] = [%s]\n",T[2]); // a만 출력
printf("T[3] = [%s]\n",T[3]); // ATMega만 출력
return 0;
}
'내장형 하드웨어 > C언어' 카테고리의 다른 글
C언어 - 고수준, 저수준 함수, write, read, open, close (0) | 2011.06.24 |
---|---|
C언어 복습 5(token, strncpy, strtok, 디버깅) (0) | 2011.06.17 |
C언어 복습(디버깅, 어셈블리 소스 작성) (0) | 2011.06.15 |
ATmega128 spec2, C언어 복습2(디버깅) (1) | 2011.06.14 |
구조체(typedef, struct), 연결리스트 (1) | 2011.05.12 |