Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. char[] problem

char[] problem

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structureshelp
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.

    char c[1000];
    for(int i ; i<1000; i++)
    c[i] =value;
    myfunc(c);

    Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.

    V D J K 4 Replies Last reply
    0
    • M Mazdak

      I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.

      char c[1000];
      for(int i ; i<1000; i++)
      c[i] =value;
      myfunc(c);

      Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      What is the parameter definition of myfunc()? Does it accept a pointer to char? myfunc(char *); Kuphryn

      M 1 Reply Last reply
      0
      • M Mazdak

        I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.

        char c[1000];
        for(int i ; i<1000; i++)
        c[i] =value;
        myfunc(c);

        Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        What is the starting value for i? Hint: it ain't 0!

        M 1 Reply Last reply
        0
        • V valikac

          What is the parameter definition of myfunc()? Does it accept a pointer to char? myfunc(char *); Kuphryn

          M Offline
          M Offline
          Mazdak
          wrote on last edited by
          #4

          kuphryn wrote: What is the parameter definition of myfunc()? Does it accept a pointer to char? myfunc(char *); myfunc(const char szbody[]); Mazy No sig. available now.

          1 Reply Last reply
          0
          • D David Crow

            What is the starting value for i? Hint: it ain't 0!

            M Offline
            M Offline
            Mazdak
            wrote on last edited by
            #5

            DavidCrow wrote: What is the starting value for i? Hint: it ain't 0! Its 0. Its just miss-typing. :-D Mazy No sig. available now.

            D 1 Reply Last reply
            0
            • M Mazdak

              I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.

              char c[1000];
              for(int i ; i<1000; i++)
              c[i] =value;
              myfunc(c);

              Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.

              J Offline
              J Offline
              jason99
              wrote on last edited by
              #6

              maybe the problem is the declaration of myfunc(), your upper code seems alright to me... is the declaration myfunc(char* c) ???? is the argument a pointer? greets, jason

              M 1 Reply Last reply
              0
              • M Mazdak

                DavidCrow wrote: What is the starting value for i? Hint: it ain't 0! Its 0. Its just miss-typing. :-D Mazy No sig. available now.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                Miss-typing and omission are two different things:

                char c[1000];
                for(int i = 0; i<1000; i++)
                c[i] =value;
                myfunc(c);

                1 Reply Last reply
                0
                • J jason99

                  maybe the problem is the declaration of myfunc(), your upper code seems alright to me... is the declaration myfunc(char* c) ???? is the argument a pointer? greets, jason

                  M Offline
                  M Offline
                  Mazdak
                  wrote on last edited by
                  #8

                  jason99 wrote: is the argument a pointer? As I said before, NO. Mazy No sig. available now.

                  D 1 Reply Last reply
                  0
                  • M Mazdak

                    jason99 wrote: is the argument a pointer? As I said before, NO. Mazy No sig. available now.

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Since arrays decay immediately into pointers, an array is never actually passed to a function. Allowing pointer parameters to be declared as arrays is a simply a way of making it look as though the array was being passed. Therefore, any parameter declarations which "look like" arrays, e.g. f( char a[]) { ... } are treated by the compiler as if they were pointers, since that is what the function will receive if an array is passed: f( char *a) { ... } This conversion holds only within function formal parameter declarations, nowhere else. If the conversion bothers you, avoid it.

                    1 Reply Last reply
                    0
                    • M Mazdak

                      I have array of characters.I want to send it as a parameters to other function and this character may contain '0',when I do it like the code below,it only pass up to '0' character.

                      char c[1000];
                      for(int i ; i<1000; i++)
                      c[i] =value;
                      myfunc(c);

                      Before the last line it containcorrect value,but in myfunc() it contain only value up to '0' value.So how can I pass it correctly? Mazy No sig. available now.

                      K Offline
                      K Offline
                      kuhx1980
                      wrote on last edited by
                      #10

                      try this: BYTE c[1000]; for (int i=0; i<1000; i++) c[i] = value; myfunc(c, 1000); and here is the definition of myfunc: void myfunc(BYTE* p, int iLen);

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups