==========================================================================================
S.C.
=======================================================================================
<C>
=typedef (:전처리 X => 끝에 반드시 ;): 별명
#include <stdio.h>
typedef unsigned int smart1; typedef unsigned long smart2;
int main() { unsigned int iNum1 = 100; unsigned long lNum1 = 1000; smart1 iNum2 = iNum1; smart2 lNum2 = lNum1;
printf("iNum1 : [%d]\n", iNum1); printf("lNum1 : [%d]\n", lNum1); printf("iNum2 : [%d]\n", iNum2); printf("lNum2 : [%d]\n", lNum2);
return 0; } |


=STRING LENGTH
-P434
#include <string.h>
typedef unsigned int size_t
size_t strlen(const char * s);
:문자열의 길이 반환



=STRING LENGTH(MY)
strlen => my_strlen 구현하기



=STRING COPY
char * strcpy(char * dest, const char * src);
char * strncpy(char * dest, const char * src, size_t n); // (최소 src 개수 / 최대 n개) 만큼
#include <stdio.h> #include <string.h>
int main() { char str1[20] = "1234567890"; char str2[20]; char str3[5];
/**** case1****/ strcpy(str2, str1); puts(str2);
/**** case2****/ strncpy(str3, str1, sizeof(str3)); puts(str3);
/**** case3****/ strncpy(str3, str1, sizeof(str3)-1); str3[sizeof(str3)-1]=0; puts(str3);
return 0; } |


#include <stdio.h> #include <string.h>
int main() { char cSrc[255]; char cDst[5]=""; scanf("%s", cSrc); strncpy(cDst, cSrc, sizeof(cDst));
printf("cSrc : %s\n", cSrc); printf("cDst : %s\n", cDst);
return 0; }
|





<구현 - 1>
#include <stdio.h>
char * my_strncpy(char * cpDst, const char * cpSrc, unsigned int uiCnt);
int main() { char cSrc[255]; char cDst[5]=""; scanf("%s", cSrc); my_strncpy(cDst, cSrc, sizeof(cDst)-1); //strncpy(cDst, cSrc, sizeof(cDst)-1);
printf("cSrc : %s\n", cSrc); printf("cDst : %s\n", cDst);
return 0; }
char * my_strncpy(char * cpDst, const char * cpSrc, unsigned int uiCnt) { char * cRet = cpDst; while(1) { if(0 == uiCnt) { break; }
if(0 == *cpSrc) { break; }
*cpDst = *cpSrc;
++cpDst; ++cpSrc; --uiCnt; }
return cRet; }
|


<구현-2>
#include <stdio.h>
char * my_strncpy(char * cpDst, const char * cpSrc, unsigned int uiCnt);
int main() { char cSrc[255]; char cDst[5]=""; scanf("%s", cSrc); my_strncpy(cDst, cSrc, sizeof(cDst)-1); //strncpy(cDst, cSrc, sizeof(cDst)-1);
printf("cSrc : %s\n", cSrc); printf("cDst : %s\n", cDst);
return 0; }
char * my_strncpy(char * cpDst, const char * cpSrc, unsigned int uiCnt) { unsigned int uiCnt2 = 0;
while(1) { if(uiCnt == uiCnt2) { break; }
if(0 == *(cpSrc+uiCnt2)) { break; }
*(cpDst+uiCnt2) = *(cpSrc+uiCnt2); ++uiCnt2; }
return cpDst; } |




==========================================================================================
디지털회로
=======================================================================================
=TEST(필기/실기)
=반가산기





=전가산기








