컥..gdbm

puaxx의 이미지

허.. 이상합니다..

코드:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <gdbm.h>

int main(int argc,char **argv){

	GDBM_FILE dbf;
	char buf[65]={0};
	datum key={0},nextkey={0},content={0};
	int ret;

	printf("Content-Type: text/html;\r\n");
	printf("\r\n");

	dbf = gdbm_open("haha", 0, GDBM_WRCREAT,0777, NULL);

	if(dbf==NULL){
		printf("gdbm open failure.\n");
		exit(1);
	}

	sprintf(buf,"%d",(int)time(NULL));
	key.dptr=(char *)calloc(0,sizeof(char)*strlen(buf)+1);
	memcpy(key.dptr,buf,strlen(buf));
	key.dsize=strlen(buf);

	printf("F: %s %d\n",key.dptr,key.dsize);

	memset(buf,0x0,65);

	sprintf(buf,"---%d---",(int)time(NULL));
	content.dptr=(char *)calloc(0,sizeof(char)*strlen(buf)+1);
	memcpy(content.dptr,buf,strlen(buf));
	content.dsize=strlen(buf);

	printf("S: %s %d\n",content.dptr,content.dsize);

	ret = gdbm_store(dbf, key, content, GDBM_INSERT);

	if(ret!=0){
		printf("An error occurred.\n");
		exit(2);
	}

	key = gdbm_firstkey ( dbf );
	while ( key.dptr ) {
		content=gdbm_fetch(dbf, key);
		printf("Contents-> %s %d\n",content.dptr,content.dsize);
		nextkey = gdbm_nextkey ( dbf, key );
		key = nextkey;
	}

	gdbm_close(dbf);

	return 0;

}

컴파일:

gcc -Wall -o test test.c -lgdbm

결과:

Content-Type: text/html;

F: 1126077459 10
S: ---1126077459--- 16
Contents-> ---1126075682--- 16
Contents-> ---1126075515--- 16
Contents-> ---1126075697--- 16
Contents-> ---1126075535--- 16
Contents-> ---1126075760--- 16
Contents-> ---1126075675--- 16
Contents-> ---1126075534--- 16
Contents-> ---1126075695--- 16
Contents-> ---1126075753--- 16
Contents-> ---1126075674--- 16
Contents-> ---1126075694--- 16
Contents-> ---1126074605--- 16
Contents-> ---1126075527--- 16
Contents-> ---1126075752--- 16
Contents-> ---1126075672--- 16
Contents-> ---1126075531--- 16
Contents-> ---1126075687--- 16
Contents-> ---1126075750--- 16
Contents-> ---1126075671--- 16
Contents-> ---1126075691--- 16
Contents-> ---1126075885--- 16
Contents-> ---1126074602--- 16
Contents-> ---1126075519--- 16
Contents-> ---1126075524--- 16
Contents-> ---1126075550--- 16
Contents-> ---1126075758--- 16
Contents-> ---1126074601--- 16
Contents-> ---1126075523--- 16
Contents-> ---1126075679--- 16
Contents-> ---1126075684--- 16
Contents-> ---1126075517--- 16
Contents-> ---1126075757--- 16
Contents-> ---1126075762--- 16
Contents-> ---1126075683--- 16
Contents-> ---1126075882--- 16
Contents-> ---1126075516--- 16
Contents-> ---1126075521--- 16
Contents-> ---1126075677--- 16
Contents-> ---1126077459--- 16
Contents-> ---1126075761--- 16
Contents-> ---1126075755--- 16
Contents-> ---1126074560--- 16
Contents-> ---1126075520--- 16
Contents-> ---1126075676--- 16
Contents-> ---1126075681--- 16
Contents-> ---1126075514--- 16
Contents-> ---1126075696--- 16
Contents-> ---1126075875--- 16
Contents-> ---1126075529--- 16
Contents-> ---1126075754--- 16
Contents-> ---1126075680--- 16
Contents-> ---1126075513--- 16
Contents-> ---1126074606--- 16
Contents-> ---1126075528--- 16
Contents-> ---1126075533--- 16
Contents-> ---1126075689--- 16
Contents-> ---1126075553--- 16
Contents-> ---1126075673--- 16
Contents-> ---1126075872--- 16
Contents-> ---1126075532--- 16
Contents-> ---1126075688--- 16
Contents-> ---1126075693--- 16
Contents-> ---1126074604--- 16
Contents-> ---1126075526--- 16
Contents-> ---1126075751--- 16
Contents-> ---1126075510--- 16
Contents-> ---1126075692--- 16
Contents-> ---1126074603--- 16
Contents-> ---1126075525--- 16
Contents-> ---1126075530--- 16
Contents-> ---1126075686--- 16
Contents-> ---1126075759--- 16
Contents-> ---1126075764--- 16
Contents-> ---1126075685--- 16
Contents-> ---1126075690--- 16
Contents-> ---1126075518--- 16
Contents-> ---1126074599--- 16
Contents-> ---1126075763--- 16
Contents-> ---1126074600--- 16
Contents-> ---1126075522--- 16
Contents-> ---1126075698--- 16
Contents-> ---1126075756--- 16

제가 gdbm라이브 러리를 가지고 테스트 한것인데요..

이상하게 데이터 순서가 뒤죽박죽으로들어가네요. 일정한 순서대로 들어갈줄 알았더니...초난감입니다 --;; 다른 라이브러리는 괜찮을까요?

제가 잘못본것일까요? 아님...

익명 사용자의 이미지

gdbm의 자료구조는 해시테이블입니다.
따라서 <key,value>쌍에서 key가 정렬상태로 저장되는 것이 아니죠

allmue의 이미지

실행할때 ./test 만 하면 되나요? ./test만 하니까요.......

F: 1200965947 10
S: ---1200965947--- 16
Segmentation fault

이렇게 나오네요.......ㅡㅡ;;;; 완전 초보라서.....이렇게 질문드립니다.

혹시 db파일을 추가해야 하나요? 아니면.....다른 실행 방법이 있나요? ㅡ.,ㅡ;;;;

죄송하게도.......질문하신 글에....질문을 남기게 됬습니다.....ㅠ_ㅠ 죄송합니다.....

_______
항상 겸손하게,
배움의 자세로 임하자.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.