structure toupper\lower?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hallvard B Furuseth

    #16
    Re: structure toupper\lower?

    Keith Thompson wrote:
    [color=blue]
    > char c = some_value;
    > c = toupper(c);[/color]

    That can crash if 'char' is signed c becomes negative (i.e. for
    non-ASCII characters if you have 8-bit bytes and an ASCII superset).
    It should be

    c = toupper((unsign ed char) c);

    --
    Hallvard

    Comment

    • Severian

      #17
      Re: structure toupper\lower?

      On Fri, 16 Jan 2004 15:05:09 GMT, pete <pfiland@mindsp ring.com> wrote:
      [color=blue]
      >CBFalconer wrote:[color=green]
      >>
      >> didgerman wrote:[color=darkred]
      >> >[/color]
      >> ... snip ...[color=darkred]
      >> >
      >> > Right, getting somewhere here.
      >> > How can I use a for loop on a struct? Without using all the
      >> > struct members.....[/color]
      >>
      >> There is an interesting "mental" process going on here. I don't
      >> think it can be ascribed to a language barrier.[/color]
      >
      >I think he's talking about using an array of offsets.
      >I've never used the offsetof() macro from stddef.h[/color]

      I've found offsetof() useful for building portable, efficient,
      table-driven, readable and easy-to-maintain access to binary files (of
      external definition). I define tables that map "natural" C structures
      to the underlying, unaligned binary data, and handle endianness (sic?)
      implicitly.

      Thus, C-aligned, native-endian structures can be read and written from
      any-endian binary files with simple calls.

      The OP could do something similar to point to the strings in the
      structs, but unless he's got dozens of structs to do this with, it's
      probably not worth the effort.

      - Sev

      Comment

      • Keith Thompson

        #18
        Re: structure toupper\lower?

        Hallvard B Furuseth <h.b.furuseth(n ospam)@usit.uio (nospam).no> writes:[color=blue]
        > Keith Thompson wrote:
        >[color=green]
        > > char c = some_value;
        > > c = toupper(c);[/color]
        >
        > That can crash if 'char' is signed c becomes negative (i.e. for
        > non-ASCII characters if you have 8-bit bytes and an ASCII superset).
        > It should be
        >
        > c = toupper((unsign ed char) c);[/color]

        Oops, you're right. Thanks.

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
        Schroedinger does Shakespeare: "To be *and* not to be"

        Comment

        • didgerman

          #19
          Re: structure toupper\lower?


          "didgerman" <aw990012@hotma il.com> wrote in message
          news:ZxGNb.4262 $JL4.31811@news fep4-glfd.server.ntl i.net...[color=blue]
          > Chaps,
          > I need to properly format the case of a struct. Can I just hit it[/color]
          with[color=blue]
          > tolower, and then 'while (string [pos]==' ')
          > pos++;
          > string[pos]=toupper(string[pos]); to add in the higher case for the
          > start of each letter?
          > The struct will contain some integers, will tolower/upper affect any
          > integers?
          >
          > Also...has anyone written an easy struct to xml converter yet?
          > Cheers for any help.
          >
          >
          >[/color]

          Chaps, I'm done, just about.
          Thnx for all the help.
          I'll continue to lurk here and pick a few things up.
          Cheers.


          Comment

          Working...