Language & DB/C
-
C FileLanguage & DB/C 2018. 12. 16. 17:06
ftell( *Fp )File객체의 현재 위치를 알려준다. fseek( )fseek( Fp, 1, SEEK_SET ) -> 파일의 맨 처음위치에서 앞으로 1Byte 이동.fseek( Fp, 1, SEEK_CUR ) -> 파일의 현재 위치에서 앞으로 1Byte 이동.fseek( Fp, -1, SEEK_END ) -> 파일의 맨 마지막 위치에서 뒤로 1Byte 이동. fgetpos( )fpos_t pos 변수fgetpos( Fp, &pos ) -> 파일객체에서 위치를 변수에 저장함.fsetpos( )fsetpos( Fp, &pos ) -> 변수에 저장된 주소로 파일객체 위치를 이동. freopen( )freopen( "file.txt", "w", stdout) -> 파일에 출력한다.
-
C언어 assert함수Language & DB/C 2018. 12. 5. 14:01
assert함수헤더: #include인자: assert( 조건 등.. )반환 값: 프로그램 종료 원인, 오류가 나오면 프로그램 중단.#include#include#include#include struct Hanja{unsigned char hanja[4];unsigned char meaning[10];unsigned char korean[4];}; int main(){int i=0;struct Hanja *c;FILE *fp;fp = fopen("8급 선정한자 훈음표.txt","r");assert(fp);c = malloc(sizeof(struct Hanja));do{fscanf(fp,"%s %s %s", c->hanja, c->meaning, c->korean);printf("%s\t%s\t%s\n",..
-
C언어 strstr함수Language & DB/C 2018. 12. 5. 12:50
strstr함수헤더파일: #include인자: strstsr(대상 문자열, 찾을 문자열) 반환 값: 찾은 문자열 시작 주소Source Code: #include#include#include int main(){FILE *fp;char buf[256], t[5], info[5][100], *cp;int i;fp = fopen("books.txt","r");if (fp == NULL){printf("File이 없습니다.");return 0;} while(1){fgets(buf, 256, fp); // 한 줄 읽기 * feof함수란 NULL을 만나기 직전까지는 0을 반환한다. if( feof(fp) ) // 끝을 만나면 멈춘다. break;printf("%s\n",buf); // buf배열을 한번에 출력. c..