strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Cunningham

    strings

    I want to write a function named after simula's outtext. I want it to
    behave exactly like printf does with strings. I have narrowed down a list of
    what funtions I think I'll need but I'm not exactly sure how to put them
    together. strlen is one isspace is another. What about alphanum ? Would it
    take care of what I want? ie

    outtext("hello world");

    hello world

    Thanks


  • Dann Corbit

    #2
    Re: strings

    "Bill Cunningham" <nospam@nspam.c omwrote in message
    news:GQxJj.77$B T1.69@trnddc04. ..
    I want to write a function named after simula's outtext. I want it to
    behave exactly like printf does with strings. I have narrowed down a list
    of what funtions I think I'll need but I'm not exactly sure how to put
    them together. strlen is one isspace is another. What about alphanum ?
    Would it take care of what I want? ie
    >
    outtext("hello world");
    >
    hello world
    You want:
    puts("hello world");



    --
    Posted via a free Usenet account from http://www.teranews.com

    Comment

    • Bill Cunningham

      #3
      Re: strings


      "Dann Corbit" <dcorbit@connx. comwrote in message
      news:47f6a188$0 $26109$88260bb3 @free.teranews. com...
      You want:
      puts("hello world");
      THanks for the wake up Dan. It would have to be that simple. Here's the
      code I wrote though because puts was wanting a cast.

      #include <stdio.h>

      int outtext(char *buffer)
      {
      printf("%s",*bu ffer);
      return 0;
      }

      Bill


      Comment

      • Dann Corbit

        #4
        Re: strings

        "Bill Cunningham" <nospam@nspam.c omwrote in message
        news:9jyJj.106$ _I1.37@trnddc02 ...
        >
        "Dann Corbit" <dcorbit@connx. comwrote in message
        news:47f6a188$0 $26109$88260bb3 @free.teranews. com...
        >
        >You want:
        >puts("hello world");
        >
        THanks for the wake up Dan. It would have to be that simple. Here's the
        code I wrote though because puts was wanting a cast.
        >
        #include <stdio.h>
        >
        int outtext(char *buffer)
        {
        printf("%s",*bu ffer);
        You don't want the contents of the pointer, but the pointer itself.
        return 0;
        }
        e.g.:
        #include <stdio.h>
        int outtext(const char *buffer)
        {
        return puts(buffer);
        }



        --
        Posted via a free Usenet account from http://www.teranews.com

        Comment

        • Bill Cunningham

          #5
          Re: strings

          >"Dann Corbit" <dcorbit@connx. comwrote in message
          >news:47f6a188$ 0$26109$88260bb 3@free.teranews .com...
          You don't want the contents of the pointer, but the pointer itself.
          >
          >return 0;
          >}
          >
          e.g.:
          #include <stdio.h>
          int outtext(const char *buffer)
          {
          return puts(buffer);
          }
          >
          So *buffer is a pointer to the location of the string while buffer is
          the pointer? I need to remember this from now on.
          Bill


          Comment

          • Dann Corbit

            #6
            Re: strings


            "Bill Cunningham" <nospam@nspam.c omwrote in message
            news:RazJj.76$3 w2.17@trnddc05. ..
            >>"Dann Corbit" <dcorbit@connx. comwrote in message
            >>news:47f6a188 $0$26109$88260b b3@free.teranew s.com...
            >
            >You don't want the contents of the pointer, but the pointer itself.
            >>
            >>return 0;
            >>}
            >>
            >e.g.:
            >#include <stdio.h>
            >int outtext(const char *buffer)
            >{
            >return puts(buffer);
            >}
            >>
            So *buffer is a pointer to the location of the string while buffer is
            the pointer? I need to remember this from now on.
            In this context, *buffer is applying the indirection or dereferencing
            operator to the string. In other words, you are going to get the first
            character of the string. That is clearly not what you want to do.



            --
            Posted via a free Usenet account from http://www.teranews.com

            Comment

            • Keith Thompson

              #7
              Re: strings

              "Bill Cunningham" <nospam@nspam.c omwrites:
              >>"Dann Corbit" <dcorbit@connx. comwrote in message
              >>news:47f6a188 $0$26109$88260b b3@free.teranew s.com...
              >
              >You don't want the contents of the pointer, but the pointer itself.
              >>
              >>return 0;
              >>}
              >>
              >e.g.:
              >#include <stdio.h>
              >int outtext(const char *buffer)
              >{
              >return puts(buffer);
              >}
              >>
              So *buffer is a pointer to the location of the string while buffer is
              the pointer? I need to remember this from now on.
              No.

              In general, unary "*" is the dereference operator. If p is a pointer,
              then *p is what p points to.

              Specifically, buffer is a pointer to char, so *buffer is a char. Not
              a pointer of any kind, just a simple character value (likely an 8-bit
              number).

              --
              Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
              Nokia
              "We must do something. This is something. Therefore, we must do this."
              -- Antony Jay and Jonathan Lynn, "Yes Minister"

              Comment

              • Bill Cunningham

                #8
                Re: strings


                "Keith Thompson" <kst-u@mib.orgwrote in message
                news:87ve2xxhm2 .fsf@kvetch.smo v.org...
                "Bill Cunningham" <nospam@nspam.c omwrites:
                >>>"Dann Corbit" <dcorbit@connx. comwrote in message
                >>>news:47f6a18 8$0$26109$88260 bb3@free.terane ws.com...
                >>
                >>You don't want the contents of the pointer, but the pointer itself.
                >>>
                >>>return 0;
                >>>}
                >>>
                >>e.g.:
                >>#include <stdio.h>
                >>int outtext(const char *buffer)
                >>{
                >>return puts(buffer);
                >>}
                >>>
                > So *buffer is a pointer to the location of the string while buffer is
                >the pointer? I need to remember this from now on.
                >
                No.
                >
                In general, unary "*" is the dereference operator. If p is a pointer,
                then *p is what p points to.
                >
                Specifically, buffer is a pointer to char, so *buffer is a char. Not
                a pointer of any kind, just a simple character value (likely an 8-bit
                number).
                Ok is const char *buffer then pointing to the first char somewhere? Or
                is the * in this case not a pointer at all but a "dereferenc e operator". I'm
                going to have to re-think everything here. No wonder I have so much trouble
                reading other's source. When I see a * I think it's a pointer to a type. In
                this case const char.


                Comment

                • Dann Corbit

                  #9
                  Re: strings

                  "Bill Cunningham" <nospam@nspam.c omwrote in message
                  news:L2AJj.86$3 w2.48@trnddc05. ..
                  >
                  "Keith Thompson" <kst-u@mib.orgwrote in message
                  news:87ve2xxhm2 .fsf@kvetch.smo v.org...
                  >"Bill Cunningham" <nospam@nspam.c omwrites:
                  >>>>"Dann Corbit" <dcorbit@connx. comwrote in message
                  >>>>news:47f6a1 88$0$26109$8826 0bb3@free.teran ews.com...
                  >>>
                  >>>You don't want the contents of the pointer, but the pointer itself.
                  >>>>
                  >>>>return 0;
                  >>>>}
                  >>>>
                  >>>e.g.:
                  >>>#include <stdio.h>
                  >>>int outtext(const char *buffer)
                  >>>{
                  >>>return puts(buffer);
                  >>>}
                  >>>>
                  >> So *buffer is a pointer to the location of the string while buffer
                  >>is
                  >>the pointer? I need to remember this from now on.
                  >>
                  >No.
                  >>
                  >In general, unary "*" is the dereference operator. If p is a pointer,
                  >then *p is what p points to.
                  >>
                  >Specifically , buffer is a pointer to char, so *buffer is a char. Not
                  >a pointer of any kind, just a simple character value (likely an 8-bit
                  >number).
                  Ok is const char *buffer then pointing to the first char somewhere? Or
                  is the * in this case not a pointer at all but a "dereferenc e operator".
                  I'm going to have to re-think everything here. No wonder I have so much
                  trouble reading other's source. When I see a * I think it's a pointer to a
                  type. In this case const char.
                  You need to differentiate between a declaration and a dereference.

                  For instance, here is a declaration of a character pointer:

                  const char *p = "p is an address that point to this string";

                  and a dereference of the object pointed to by pointer p like this:

                  char c = *p; /* get the first char of p and store it in c */



                  --
                  Posted via a free Usenet account from http://www.teranews.com

                  Comment

                  Working...