C에서 다음과 같은 데이터 테이블을 표현 하려면 어떻게 하나요?

zaru의 이미지

R1,  R2,  R3,    R4, R5,  R6 <-- 편의상 붙임.
0.15,0.15,117000,200,2500,9.70 <-- 1행
0.20,0.20,115000,160,1000,8.83 <-- 2행
0.95,1.00,55000,520,5000,4.31
1.00,1.00,52000,520,5000,4.09
1.05,1.00,45000,520,5000,3.55
1.95,2.00,24000,360,5000,1.91
2.00,2.00,24000,360,5000,1.91
2.90,2.90,20000,270,5000,1.60
2.95,3.10,20000,270,5000,1.60
3.00,3.10,20000,220,5000,1.60
3.90,4.00,20000,140,5000,1.60
3.95,4.00,20000,140,5000,1.60
4.00,4.00,20000,130,5000,1.60
4.05,4.00,20000,130,5000,1.60
4.10,4.40,20000,130,5000,1.60
5.00,5.00,20000,130,5000,1.60
5.05,5.00,20000,130,5000,1.60
5.10,5.10,20000,130,5000,1.60
6.00,6.00,20000,130,5000,1.60
6.05,6.10,20000,130,5000,1.60
6.10,6.10,20000,130,5000,1.60

위와 같이 콤마로 구분된 데이터가 있습니다. C에서 R1에 해당하는 R2~R6 까지의 값을 찾아 쓸려고 할 때 데이터 표현을 어떻게 해야 하는지요?
lifthrasiir의 이미지

zaru wrote:
R1,  R2,  R3,    R4, R5,  R6 <-- 편의상 붙임.
0.15,0.15,117000,200,2500,9.70 <-- 1행
0.20,0.20,115000,160,1000,8.83 <-- 2행
0.95,1.00,55000,520,5000,4.31
1.00,1.00,52000,520,5000,4.09
1.05,1.00,45000,520,5000,3.55
1.95,2.00,24000,360,5000,1.91
2.00,2.00,24000,360,5000,1.91
2.90,2.90,20000,270,5000,1.60
2.95,3.10,20000,270,5000,1.60
3.00,3.10,20000,220,5000,1.60
3.90,4.00,20000,140,5000,1.60
3.95,4.00,20000,140,5000,1.60
4.00,4.00,20000,130,5000,1.60
4.05,4.00,20000,130,5000,1.60
4.10,4.40,20000,130,5000,1.60
5.00,5.00,20000,130,5000,1.60
5.05,5.00,20000,130,5000,1.60
5.10,5.10,20000,130,5000,1.60
6.00,6.00,20000,130,5000,1.60
6.05,6.10,20000,130,5000,1.60
6.10,6.10,20000,130,5000,1.60

위와 같이 콤마로 구분된 데이터가 있습니다. C에서 R1에 해당하는 R2~R6 까지의 값을 찾아 쓸려고 할 때 데이터 표현을 어떻게 해야 하는지요?

그냥 struct로 다음과 같이 정의하고 binary search를 사용하세요.

typedef struct {
    float R1, R2;
    int R3, R4, R5;
    float R6;
} data_t;

STL의 map 같은 자료 구조를 C에서도 쓸 수 있게 만든 라이브러리가 있는 지는 모르겠습니다.

- 토끼군

doldori의 이미지

tokigun wrote:
STL의 map 같은 자료 구조를 C에서도 쓸 수 있게 만든 라이브러리가 있는 지는 모르겠습니다.

GLib의 balanced binary tree를 쓰면 되지 않을까요?
mr.lee의 이미지

엉뚱한 대답일련진 모르겠지만,,

DB에 넣고 SELECT 하는건 어떨까요..

DB서버가 없다면 SQLite가 좋은 대안이 되겠지요.

익명 사용자의 이미지

{key, value}의 페어를 가지는 구조로 bdb, gdbm등을 사용하면 되겠군요.
hash도 좋고, 키값들간에 어떤 순서(관계)가 있다고 가정한다면, BTREE나 그 변종도 좋겠습니다. 만일 그렇다면, splaytree같은 것도 좋겠군요.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.