Create readonly array of data?

Discussion in 'C Programming' started by Susan Rice, Jan 1, 2007.

  1. Susan Rice

    Susan Rice Guest

    I want to create a readonly array of data, then a readonly array of a
    structure. This is data I access but I want it protected against
    accidental change. The following is my test code.

    #include "stdafx.h"

    struct LVC
    {
    unsigned short int lo;
    unsigned short int hi;
    };

    void main()
    {
    //This seems to work
    static const unsigned short int LV[4] =
    {0xAC00,
    0xAC1C,
    0xAC38,
    0xAC54 };

    //THIS DOESN'T WORK. COMPILER COMPLAINS
    static const struct LVC[4] = {
    { 0xAC01, 0xAC1B },
    { 0xAC1D, 0xAC37 },
    { 0xAC39, 0xAC53 },
    { 0xAC55, 0xAC6F },
    };

    unsigned short i,j;

    i = LVC[2].lo;
    j = LVC[2].hi;
    }

    I'm using Microsoft Visual C++ Express Edition
    (I'd also like to get rid of that #include "stdafx.h" if
    there's some compiler configuration that will allow me
    to do that.)
    Susan Rice, Jan 1, 2007
    #1
    1. Advertising

  2. Susan Rice

    jacob navia Guest

    Susan Rice a écrit :
    > //THIS DOESN'T WORK. COMPILER COMPLAINS
    > static const struct LVC[4] = {

    static const struct LVC is the type. You have to give a *name*
    to that array.

    for instance
    static const struct LVC MyTable[4] = {
    etc

    Then you use THAT name:
    i = MyTable[2].lo;
    j = MyTable[2].hi;

    jacob

    P.S.
    it is not void main() but int main(void).
    But that is a detail.

    ---
    http://www.cs.virginia.edu/~lcc-win32
    A free C compiler for windows
    jacob navia, Jan 1, 2007
    #2
    1. Advertising

  3. Susan Rice

    Default User Guest

    Susan Rice wrote:

    > I want to create a readonly array of data, then a readonly array of a
    > structure. This is data I access but I want it protected against
    > accidental change. The following is my test code.
    >
    > #include "stdafx.h"


    See below about this.

    > struct LVC


    It's generally prefered by most to reserve all caps for macros.

    > {
    > unsigned short int lo;
    > unsigned short int hi;
    > };
    >
    > void main()


    This should be int main(void)

    > {
    > //This seems to work
    > static const unsigned short int LV[4] =
    > {0xAC00,
    > 0xAC1C,
    > 0xAC38,
    > 0xAC54 };
    >
    > //THIS DOESN'T WORK. COMPILER COMPLAINS
    > static const struct LVC[4] = {


    LVC is the name of struct type that you created above. What you wanted
    was something like:

    static const struct LVC LVC_array[4] = {

    > { 0xAC01, 0xAC1B },
    > { 0xAC1D, 0xAC37 },
    > { 0xAC39, 0xAC53 },
    > { 0xAC55, 0xAC6F },
    > };
    >
    > unsigned short i,j;
    >
    > i = LVC[2].lo;
    > j = LVC[2].hi;


    Then change these two names as well.

    > }
    >
    > I'm using Microsoft Visual C++ Express Edition
    > (I'd also like to get rid of that #include "stdafx.h" if
    > there's some compiler configuration that will allow me
    > to do that.)


    This has to do with pre-compiled headers in VC++. I don't know
    specifically to correct that in Express, but check your project
    settings to remove any dependence. If you can't figure it out, you'll
    need a Microsoft newsgroup.




    Brian
    Default User, Jan 1, 2007
    #3
  4. Susan Rice

    rhle.freak Guest

    I'm using Microsoft Visual C++ Express Edition
    > (I'd also like to get rid of that #include "stdafx.h" if
    > there's some compiler configuration that will allow me
    > to do that.)


    when u create your project in msvc++

    new project->Win32(win32 console app template is automatically
    selected) ->
    (enter a name for the project)->next->select "empty project"
    option->finish

    then add the header and source files that u need.

    and more simply...
    new project->select "general " option from the Project type window
    ->finish

    //THIS DOESN'T WORK. COMPILER COMPLAINS
    static const struct LVC[4] = {
    { 0xAC01, 0xAC1B },
    u did not name the "template" ..it has been answered above

    regards
    rhle.freak, Jan 1, 2007
    #4
  5. Susan Rice

    CBFalconer Guest

    "rhle.freak" wrote:
    >
    >> I'm using Microsoft Visual C++ Express Edition
    >> (I'd also like to get rid of that #include "stdafx.h" if
    >> there's some compiler configuration that will allow me
    >> to do that.)

    >
    > when u create your project in msvc++


    U never posted in this thread. I don't believe he even uses
    c.l.c. If you refrained from snipping attributions it would be
    easier to follow this. In addition msvc++ is system specific and
    off-topic here.

    --
    Merry Christmas, Happy Hanukah, Happy New Year
    Joyeux Noel, Bonne Annee.
    Chuck F (cbfalconer at maineline dot net)
    <http://cbfalconer.home.att.net>
    CBFalconer, Jan 1, 2007
    #5
  6. CBFalconer said:

    > "rhle.freak" wrote:
    >>
    >>> I'm using Microsoft Visual C++ Express Edition
    >>> (I'd also like to get rid of that #include "stdafx.h" if
    >>> there's some compiler configuration that will allow me
    >>> to do that.)

    >>
    >> when u create your project in msvc++

    >
    > U never posted in this thread. I don't believe he even uses
    > c.l.c.


    I believe he has done so (although I admit it may have been cp rather than
    clc) - a month or so ago.


    > If you refrained from snipping attributions it would be
    > easier to follow this. In addition msvc++ is system specific and
    > off-topic here.


    Will you not take pity on someone who appears to be trying to coax his
    Microsoft implementation into conforming mode?

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
    Richard Heathfield, Jan 1, 2007
    #6
  7. "rhle.freak" <> writes:
    [...]
    > when u create your project in msvc++

    [...]
    > then add the header and source files that u need.

    [...]
    > u did not name the "template" ..it has been answered above


    Please don't use silly abbreviations like "u" for "you". It makes
    your articles harder to read, and a lot of people just won't bother.

    And please don't snip attribution lines (lines of the form
    "So-and-so writes:").

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Jan 1, 2007
    #7
  8. Susan Rice

    rhle.freak Guest

    On Jan 1, 7:57 pm, CBFalconer <> wrote:
    > "rhle.freak" wrote:
    >
    > >> I'm using Microsoft Visual C++ Express Edition
    > >> (I'd also like to get rid of that #include "stdafx.h" if
    > >> there's some compiler configuration that will allow me
    > >> to do that.)

    >
    > > when u create your project in msvc++U never posted in this thread. I don't believe he even uses

    > c.l.c. If you refrained from snipping attributions it would be
    > easier to follow this. In addition msvc++ is system specific and
    > off-topic here.
    >
    > --


    please do check the earlier thread "stack" which i had posted a few
    days ago! ! regarding using msvc++ ,yes its a specific problem and off
    topic but there is no harm if i am using the same compiler n can help
    someone with something really simple and please do forgive me because
    i am new to using Usenet
    (Google groups to be specific) and my format of posting was wrong,i
    will definitely try to improve on that!!
    rhle.freak, Jan 2, 2007
    #8
  9. Susan Rice

    CBFalconer Guest

    "rhle.freak" wrote:
    > CBFalconer <> wrote:
    >> "rhle.freak" wrote:
    >>
    >>> I'm using Microsoft Visual C++ Express Edition
    >>> (I'd also like to get rid of that #include "stdafx.h" if
    >>> there's some compiler configuration that will allow me
    >>> to do that.)

    >>
    >>> when u create your project in msvc++

    >>
    >> U never posted in this thread. I don't believe he even uses
    >> c.l.c. If you refrained from snipping attributions it would be
    >> easier to follow this. In addition msvc++ is system specific and
    >> off-topic here.

    >
    > please do check the earlier thread "stack" which i had posted a few
    > days ago! ! regarding using msvc++ ,yes its a specific problem and off
    > topic but there is no harm if i am using the same compiler n can help
    > someone with something really simple and please do forgive me because
    > i am new to using Usenet
    > (Google groups to be specific) and my format of posting was wrong,i
    > will definitely try to improve on that!!


    'Another thread' has nothing to do with it. Articles need to stand
    alone. That is the point of quoting relevant matter. You would be
    well advised to get a proper newsreader and access usenet directly
    instead of through the flawed google interface. Also never use
    silly geekspeak, such as 'u' and 'n' abbreviations. They only
    serve to annoy and make reading hard, especially for non-English
    speakers.

    Just delete the #include <stdafx.h> and #include the appropriate
    standard C includes. The C-library link below will be useful, as
    will the C99 standard.

    Some useful references about C:
    <http://www.ungerhu.com/jxh/clc.welcome.txt>
    <http://www.eskimo.com/~scs/C-faq/top.html>
    <http://benpfaff.org/writings/clc/off-topic.html>
    <http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
    <http://www.dinkumware.com/refxc.html> (C-library}
    <http://gcc.gnu.org/onlinedocs/> (GNU docs)
    <http://clc-wiki.net> (C-info)

    Some informative links about posting:
    <http://members.fortunecity.com/nnqweb/> (newusers)
    <http://www.catb.org/~esr/faqs/smart-questions.html>
    <http://www.caliburn.nl/topposting.html>
    <http://www.netmeister.org/news/learn2quote.html>
    <http://cfaj.freeshell.org/google/> (taming google)

    --
    Merry Christmas, Happy Hanukah, Happy New Year
    Joyeux Noel, Bonne Annee.
    Chuck F (cbfalconer at maineline dot net)
    <http://cbfalconer.home.att.net>
    CBFalconer, Jan 2, 2007
    #9
  10. CBFalconer wrote:
    > "rhle.freak" wrote:
    > > CBFalconer <> wrote:
    > >> "rhle.freak" wrote:


    <snip>

    > alone. That is the point of quoting relevant matter. You would be
    > well advised to get a proper newsreader and access usenet directly
    > instead of through the flawed google interface. Also never use


    <snip>

    How do I access usenet directly?
    For free ?

    Regards,
    Frodo B
    Frodo Baggins, Jan 2, 2007
    #10
  11. Susan Rice

    CBFalconer Guest

    Frodo Baggins wrote:
    > CBFalconer wrote:
    >
    > <snip>
    >
    >> alone. That is the point of quoting relevant matter. You would be
    >> well advised to get a proper newsreader and access usenet directly
    >> instead of through the flawed google interface. Also never use

    >
    > <snip>
    >
    > How do I access usenet directly? For free ?


    Your ISP should provide that. Ask them, and they will also tell
    you what the servers URL is. This is to be accessed by a news
    reader, not a browser. If they don't provide a server they are not
    a proper ISP, but you have the recourse of various free
    newservers. Others exist, and people may chime in with their URLs.

    Some free news servers
    <http://www.teranew.com> (free)
    <http://www.newsfeeds.com/signup.htm> (pay)

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
    CBFalconer, Jan 2, 2007
    #11
  12. Susan Rice

    Default User Guest

    CBFalconer wrote:


    > Some free news servers
    > <http://www.teranew.com> (free)


    <http://www.teranews.com/>
    ^
    That 's' makes a lot of difference.




    Brian
    Default User, Jan 2, 2007
    #12
  13. Susan Rice

    Nelu Guest

    CBFalconer wrote:
    > Frodo Baggins wrote:
    >> CBFalconer wrote:
    >>
    >> <snip>
    >>
    >>> alone. That is the point of quoting relevant matter. You would be
    >>> well advised to get a proper newsreader and access usenet directly
    >>> instead of through the flawed google interface. Also never use

    >> <snip>
    >>
    >> How do I access usenet directly? For free ?

    >
    > Your ISP should provide that. Ask them, and they will also tell
    > you what the servers URL is. This is to be accessed by a news
    > reader, not a browser. If they don't provide a server they are not
    > a proper ISP, but you have the recourse of various free
    > newservers. Others exist, and people may chime in with their URLs.
    >
    > Some free news servers
    > <http://www.teranew.com> (free)
    > <http://www.newsfeeds.com/signup.htm> (pay)
    >


    http://news.aioe.org

    --
    Ioan - Ciprian Tandau
    tandau _at_ freeshell _dot_ org (hope it's not too late)
    (... and that it still works...)
    Nelu, Jan 2, 2007
    #13
  14. Susan Rice

    Randy Howard Guest

    On Tue, 2 Jan 2007 06:06:43 -0600, Frodo Baggins wrote
    (in article <>):

    >
    > CBFalconer wrote:
    >> "rhle.freak" wrote:
    >>> CBFalconer <> wrote:
    >>>> "rhle.freak" wrote:

    >
    > <snip>
    >
    >> alone. That is the point of quoting relevant matter. You would be
    >> well advised to get a proper newsreader and access usenet directly
    >> instead of through the flawed google interface. Also never use

    >
    > <snip>
    >
    > How do I access usenet directly?


    It depends upon your ISP generally.

    > For free ?


    That depends upon how you define free(). :)

    If your ISP bundles it into the price of your normal access fees, you
    might consider it to be free in that context, as I do.

    You'll probably need to look on the ISP's website support page (if any)
    for things like "News server", or "NNTP".

    It's usually something like:

    news.ispdomainname.com

    And may or may not require a user id and password for authentication.

    As for suitable newsreaders, that depends upon your operating system.
    Some examples of newsreaders are:

    Windows: Gravity, SuperGravity, Agent, Thunderbird, Outlook Express
    OS X: Hogwasher, MTNewswatcher, Thunderbird
    Linux: A ton of them, including Thunderbird, slrn, trn, nn, xrn, and
    many more.

    In all almost all cases, the interface provided to Usenet is vastly
    superior to that of Google.

    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw
    Randy Howard, Jan 2, 2007
    #14
  15. Susan Rice

    rhle.freak Guest

    On Jan 3, 1:42 am, Nelu <> wrote:
    > CBFalconer wrote:
    > > Frodo Baggins wrote:
    > >> CBFalconer wrote:

    >
    > >> <snip>


    http://news.aioe.org

    thank you! i had the Thunderbird client for long ;was looking for a
    news server .this is just fine!!
    rhle.freak, Jan 3, 2007
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jeff h. silverman
    Replies:
    1
    Views:
    297
    Roedy Green
    Jul 28, 2003
  2. Replies:
    7
    Views:
    388
  3. Replies:
    0
    Views:
    341
  4. Jonathan Hyatt
    Replies:
    1
    Views:
    1,861
    Jonathan Hyatt
    Jun 8, 2004
  5. paolo

    Create readonly array of data ?

    paolo, Jan 2, 2012, in forum: C Programming
    Replies:
    5
    Views:
    475
    Roberto Waltman
    Jan 4, 2012
Loading...

Share This Page