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. Array Size

Array Size

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++data-structures
20 Posts 7 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.
  • T Offline
    T Offline
    TeVc
    wrote on last edited by
    #1

    Hi All I am new in vc++.I have a problem to get length of array.Plz help me

    M T K CPalliniC 4 Replies Last reply
    0
    • T TeVc

      Hi All I am new in vc++.I have a problem to get length of array.Plz help me

      M Offline
      M Offline
      MANISH RASTOGI
      wrote on last edited by
      #2

      sizeof();

      T 1 Reply Last reply
      0
      • T TeVc

        Hi All I am new in vc++.I have a problem to get length of array.Plz help me

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        CArray or user defined array??

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/xml>

        T 1 Reply Last reply
        0
        • M MANISH RASTOGI

          sizeof();

          T Offline
          T Offline
          TeVc
          wrote on last edited by
          #4

          Thanks for reply but it's not working i have a CString store[100];,CString File; and int cou=0;. And i use store[cou]=File. And i want to get Size of store[cou].Plz help me

          M 1 Reply Last reply
          0
          • T ThatsAlok

            CArray or user defined array??

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
            Never mind - my own stupidity is the source of every "problem" - Mixture

            cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/xml>

            T Offline
            T Offline
            TeVc
            wrote on last edited by
            #5

            User define Array

            L 1 Reply Last reply
            0
            • T TeVc

              User define Array

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              do you want the size of the array in bytes, or the number of elements in the array? if you want the size in bytes, use the sizeof() like so;

              int size_in_bytes;
              int theArray[20];
              size_in_bytes = sizeof(theArray);

              S 1 Reply Last reply
              0
              • L Lost User

                do you want the size of the array in bytes, or the number of elements in the array? if you want the size in bytes, use the sizeof() like so;

                int size_in_bytes;
                int theArray[20];
                size_in_bytes = sizeof(theArray);

                S Offline
                S Offline
                santhoshv84
                wrote on last edited by
                #7

                Hi, Dont use user defined array in this case. You better use CStringArray. Then you no need to calculate the size of the array. This class is having a member function int GetSize() to get the size of the array.

                The price of anything is the amount of life you exchange for it. Thanks and Regards. SANTHOSH V

                1 Reply Last reply
                0
                • T TeVc

                  Hi All I am new in vc++.I have a problem to get length of array.Plz help me

                  K Offline
                  K Offline
                  KarstenK
                  wrote on last edited by
                  #8

                  please read at first the docs about the used obejcts carefully. Often there are tiny little helper as .length or .GetLength to solve such problems. (And use the search box in top of this site a lot) :-\

                  Greetings from Germany

                  1 Reply Last reply
                  0
                  • T TeVc

                    Hi All I am new in vc++.I have a problem to get length of array.Plz help me

                    CPalliniC Online
                    CPalliniC Online
                    CPallini
                    wrote on last edited by
                    #9

                    What kind of array are you using? Could you please post array declaration? :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    In testa che avete, signor di Ceprano?

                    T 1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      What kind of array are you using? Could you please post array declaration? :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      T Offline
                      T Offline
                      TeVc
                      wrote on last edited by
                      #10

                      CString store[100];,

                      CPalliniC 1 Reply Last reply
                      0
                      • T TeVc

                        CString store[100];,

                        CPalliniC Online
                        CPalliniC Online
                        CPallini
                        wrote on last edited by
                        #11

                        The size of such array is

                        int iSize = sizeof(store);

                        The number of elements of such array is

                        int iCount = sizeof(store)/sizeof(store[0]);

                        or, more concisely, 100. :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        In testa che avete, signor di Ceprano?

                        T 1 Reply Last reply
                        0
                        • CPalliniC CPallini

                          The size of such array is

                          int iSize = sizeof(store);

                          The number of elements of such array is

                          int iCount = sizeof(store)/sizeof(store[0]);

                          or, more concisely, 100. :)

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                          [My articles]

                          T Offline
                          T Offline
                          TeVc
                          wrote on last edited by
                          #12

                          Thanks for reply but it's not working.

                          CString store[100];
                          CString File;
                          and int cou=0;
                          store[cou]=File.

                          File name added at the run time.Plz help me

                          CPalliniC 1 Reply Last reply
                          0
                          • T TeVc

                            Thanks for reply but it's not working.

                            CString store[100];
                            CString File;
                            and int cou=0;
                            store[cou]=File.

                            File name added at the run time.Plz help me

                            CPalliniC Online
                            CPalliniC Online
                            CPallini
                            wrote on last edited by
                            #13

                            What does it mean 'it's not working?' in such context? What are you trying to do? What happens instead? :)

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                            [My articles]

                            In testa che avete, signor di Ceprano?

                            T 1 Reply Last reply
                            0
                            • CPalliniC CPallini

                              What does it mean 'it's not working?' in such context? What are you trying to do? What happens instead? :)

                              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                              [My articles]

                              T Offline
                              T Offline
                              TeVc
                              wrote on last edited by
                              #14

                              store[cou]=File;

                              int iSize=sizeof(store);

                              AfxMessageBox(iSize);

                              Then i am geting Debug Assertion Fail Line number:163.

                              CPalliniC 1 Reply Last reply
                              0
                              • T TeVc

                                store[cou]=File;

                                int iSize=sizeof(store);

                                AfxMessageBox(iSize);

                                Then i am geting Debug Assertion Fail Line number:163.

                                CPalliniC Online
                                CPalliniC Online
                                CPallini
                                wrote on last edited by
                                #15

                                On what line does the code assert? BTW your array is fixed-sized to 100 elements, regardless if you assign or not any of them. :)

                                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                [My articles]

                                In testa che avete, signor di Ceprano?

                                T 1 Reply Last reply
                                0
                                • CPalliniC CPallini

                                  On what line does the code assert? BTW your array is fixed-sized to 100 elements, regardless if you assign or not any of them. :)

                                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                  [My articles]

                                  T Offline
                                  T Offline
                                  TeVc
                                  wrote on last edited by
                                  #16

                                  Thank Now it is working.Your code is good.I make a mistake.SO thanks again.Ome more question how can i use dynamic array.Plz help me

                                  CPalliniC 1 Reply Last reply
                                  0
                                  • T TeVc

                                    Thank Now it is working.Your code is good.I make a mistake.SO thanks again.Ome more question how can i use dynamic array.Plz help me

                                    CPalliniC Online
                                    CPalliniC Online
                                    CPallini
                                    wrote on last edited by
                                    #17

                                    If you need an array that grows dynamically then have a look at std::vector. MFC has the CArray container but it's a crap (please don't tell this to Rajesh :rolleyes: ). very basic (and naive) vector usage sample follows:

                                    #include <iostream>
                                    #include <string>
                                    #include <vector>

                                    using namespace std;
                                    void main()
                                    {

                                    vector < string > v;

                                    v.push_back(string("hi,"));
                                    v.push_back(string("how"));
                                    v.push_back(string("do you do?"));
                                    cout << "vector size = " << v.size() << endl;
                                    for (int i=0; i<v.size(); i++)
                                    {
                                    cout << v[i] << " ";
                                    }
                                    cout << endl;
                                    }

                                    :)

                                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                    [My articles]

                                    In testa che avete, signor di Ceprano?

                                    T 1 Reply Last reply
                                    0
                                    • CPalliniC CPallini

                                      If you need an array that grows dynamically then have a look at std::vector. MFC has the CArray container but it's a crap (please don't tell this to Rajesh :rolleyes: ). very basic (and naive) vector usage sample follows:

                                      #include <iostream>
                                      #include <string>
                                      #include <vector>

                                      using namespace std;
                                      void main()
                                      {

                                      vector < string > v;

                                      v.push_back(string("hi,"));
                                      v.push_back(string("how"));
                                      v.push_back(string("do you do?"));
                                      cout << "vector size = " << v.size() << endl;
                                      for (int i=0; i<v.size(); i++)
                                      {
                                      cout << v[i] << " ";
                                      }
                                      cout << endl;
                                      }

                                      :)

                                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                      [My articles]

                                      T Offline
                                      T Offline
                                      TeVc
                                      wrote on last edited by
                                      #18

                                      Thanks for help.Every reply boost me..

                                      CPalliniC 1 Reply Last reply
                                      0
                                      • T TeVc

                                        Thanks for help.Every reply boost me..

                                        CPalliniC Online
                                        CPalliniC Online
                                        CPallini
                                        wrote on last edited by
                                        #19

                                        :)

                                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                        [My articles]

                                        In testa che avete, signor di Ceprano?

                                        1 Reply Last reply
                                        0
                                        • T TeVc

                                          Thanks for reply but it's not working i have a CString store[100];,CString File; and int cou=0;. And i use store[cou]=File. And i want to get Size of store[cou].Plz help me

                                          M Offline
                                          M Offline
                                          MANISH RASTOGI
                                          wrote on last edited by
                                          #20

                                          store[cou].GetLength()

                                          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