Structure 어떻게 사용하세요?

smileng의 이미지

자료형중에서 구조체에 관해서 얘기해보고자 합니다.^^
여러분들은 어떻게 사용하세요?

저의 경우는...

struct _Contact
{
    int iNum;
    char strDisplayName[128];
    char strLastName[64];
    char strFirstName[64];
};
typedef struct _Contact CONTACT;
typedef CONTACT * Contact;

or
struct _Contact
{
    int iNum;
    char *szDisplayName;
    char *szLastName;
    char *szFirstName;
};
typedef struct _Contact CONTACT;
typedef CONTACT * Contact;

이렇게 사용합니다.(아직 자료형 꾸미는것도, 헝가리안도 서툽니다.ㅡㅡ)
자료형을 쓰는데 지적좀 해주세요.

위에 것은 하나하나 memset()으로 초기화해주고 썼었는데...자료가 많아지니까 쌩고생하게 되더라구요.
아래것은 이렇게 써야하는건지 분별조차 안됩니다.ㅡㅡ;초기화는 어떻게 시켜줄것이며,
그런데...만약에...char형 문자가 아주아주 길게 들어가야 한다면
아래 것이 더 좋은거 같은데...동적이란 매력 때문에..

여러분들은 어떻게 사용하세요?

dudungsil의 이미지

구조체에 대한 질문이 아니라 구조체 안에 넣는 문자열에 대한것이군요.
상황에 따라 다르지만 일단 기본적으로는

typedef struct _CONTACT
{
    int     number;
    char  displayName[xx];
    char  lastName[xx];
    char  firstName[xx];
    //
} CONTACT, *PCONTACT;

와 같은 식으로 씁니다. xx의 크기에 관계없이 구조체라면 거의 배열로 잡습니다. 동적으로 할당해야는 경우라면 class를 사용합니다. 그리고 char * 보다는 std::string을 쓰겠죠.

문자열에 char * 써본지 오래됐네요. char *형이라면 주로 바이너리 데이터를 쓰는데 사용합니다.

산넘어 산

zelon의 이미지

네.. 일단 저도 동적할당은 최대한 피하는 입장입니다. 바로 위에 분 처럼 문자열은 최대한 std::string 을 쓰고, 최대한 정적 배열을 쓰며, 될 수 있는 한 local 변수를 씁니다.

요즘은 효율측면보다 코드 관리 측면을 많이 선호하는 편이라서요. 물론 임베디드 환경처럼 메모리나 CPU 가 조금 부족하다면 한번 더 생각해봐야겠죠^^

-----------------------------------------------------------------------
GPL 오픈소스 윈도우용 이미지 뷰어 ZViewer - http://zviewer.wimy.com
블로그 : http://blog.wimy.com

댓글 달기

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