Thread: allocation and reallocation of memory dynamically of an integer array

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    allocation and reallocation of memory dynamically of an integer array

    Write a program in which you have to:
    1. Dynamically allocate an array of integers.
    2. Take array size as input from user and allocate memory according to this size.
    3. Take values of array elements as an input from user.
    4. Print all array values.
    5. In this step; double the previous array size (taken in step 2) and reallocate memory for the array according to new array size. For example if user provided array size is 4; now it will become 8, i.e. allocate memory for array having size 8.

    6. Now again take values for second half of the array as an input from the user to fill the increased size of an array.(You have already taken the values of first half of the array elements in step 3, now take values for remaining elements i.e. Second half).
    7. Print all values of the array.
    8. Also confirm that first half values of array are same in both printout statements (step 3 and step 7).


    Sample Output
    Program to dynamically Allocates an array of integers.
    Enter the size of the array: 4
    Enter a value: 1
    Enter a value: 2
    Enter a value: 3
    Enter a value: 4


    The elements of the array are:
    1 2 3 4

    Enter the elements in the array after reallocation:
    Enter a value: 5
    Enter a value: 6
    Enter a value: 7
    Enter a value: 8

    1 2 3 4 5 6 7 8
    Last edited by zamir; 05-26-2009 at 04:58 PM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And what have you done of that, and what have you got problems with?

    It's no good posting your assignment here, we do not do other people's homework. The way it works is that you show us that you are TRYING to solve it yourself, and we help you a bit at a time.


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    I like you your post has no question marks
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    147
    Every time I see a post like this, with just the assignment and maybe a "do this for me" or similar message, I think of Back to the Future; Biff, complaining that he has to have time to re-write the report in his own handwriting.....

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by JVene View Post
    Every time I see a post like this, with just the assignment and maybe a "do this for me" or similar message, I think of Back to the Future; Biff, complaining that he has to have time to re-write the report in his own handwriting.....
    Every time I see a post like that, I can imagine the OP saying "Do you want fries with that?"
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  6. #6
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    You can just imagine his resume:

    Code:
    ** Skateboarding ** Juggling ** Totally mad computer skillz

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    2
    Dear it is my assignment i have done the alot of effort to solve this but it dose give me the exect excuition.Plz if some the above solve the assignment and well give me the code.I have use a for loop first and then again i have tried to print the integers in bold but it dose not work then i tried again that to reallocate the memory for the integer i have allocated it also but it also do not give me reallcation value.now if there there is some one to give me the right code

  8. #8
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    oh god lol
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right, you obviously didn't understand the first reply, so I will be a bit more direct and clear:
    1. You post the code you have at the moment.
    2. You tell us exactly what you have a problem with
    is it compiling or not, if not what error messages;
    is it crashing, what do you need to do to make it crash;
    is it producing a different result than you expect, what does it produce, and what do you expect

    We do not "do" other peoples homework. It is unethical to do that, and whilst YOU may not care, we do get to work with the people that come out of the schools, and if all those people know how to do is go on the internet and ask someone else to do it for them, it's not going to be good!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    6

    Restrict user to enter only numeric entries

    Hi,


    I need to know about how to restrict users to enter only numeric entries only and when the user enter the alphabetic character it exit the loop. I want to use the function for it.

    I want to use it while getting the input of getting the size of array from user. If a user enter the alphabetic entry it doesn't execute the function and ask again for the numeric entry.

    Regards
    Last edited by funky; 05-28-2009 at 10:40 PM.

  11. #11
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by funky View Post
    Hi,


    I need to know about how to restrict users to enter only numeric entries only and when the user enter the alphabetic character it exit the loop. I want to use the function for it.

    I want to use it while getting the input of getting the size of array from user. If a user enter the alphabetic entry it doesn't execute the function and ask again for the numeric entry.

    Regards
    and you thought it was appropriate to post that in this topic because . . . ?
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    6

    Dunno the meaning of your because

    Well, If cudn't get the meaning of your because here.

    & if you are saying that why I haven't posted my code here, is because of the reason that I had made it with hard work & it's the same assignment about which the query is already posted here, so I don't want any one other to copy my assignment. Once the date for that assignment will be over i'll copy the code too.

    Therefore i only queried for the loop here. I think this explanation is enough for your because. Need more explanations kindly post.

    Regards

  13. #13
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Obviously trying as hard at programming as at English, and I'm sure that English is this person's first language, as evidenced by things like "Dunno".
    I get the feeling that the education system has gone downhill lately.

    Signing up under two different user names isn't going to get you any brownie points here...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  14. #14
    Registered User
    Join Date
    May 2009
    Posts
    6

    Rule of Proper Grammar

    Well iMalc or whatever your name is, this is the dilemma of the nation that they relate bieng Educated with the person who know English well and dunno (for your convenience don't know) the manners.

    Kindly let me know where is it written that English is mandatory to be the part of this forum & better make your decisions on some concrete points rather than assumptions.

    I am not the same user & if I have to ask anything I have the guts to ask it open rather than hiding myself with different user names.

    I joined this forum because i like people here don't make other people just copy the stuff but help them for good. But I am sorry to see that people here just mean to insult the others rather than bieng cooperative.

    And yes have the English teaching classes for the users here so that they can come up to your expectations (the educated people)

    Regards,

  15. #15
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by funky View Post
    Well iMalc or whatever your name is, this is the dilemma of the nation that they relate bieng Educated with the person who know English well and dunno (for your convenience don't know) the manners.

    Kindly let me know where is it written that English is mandatory to be the part of this forum & better make your decisions on some concrete points rather than assumptions.

    I am not the same user & if I have to ask anything I have the guts to ask it open rather than hiding myself with different user names.

    I joined this forum because i like people here don't make other people just copy the stuff but help them for good. But I am sorry to see that people here just mean to insult the others rather than bieng cooperative.

    And yes have the English teaching classes for the users here so that they can come up to your expectations (the educated people)

    Regards,
    your post is making my eyes bleed, please pay attention to the red underline (not like that will fix half your problems though)

    I am not the same user & if I have to ask anything I have the guts to ask it open rather than hiding myself with different user names.
    Then make your own dam thread

    Quote Originally Posted by funky View Post
    have the English teaching classes for the users here so that they can come up to your expectations (the educated people
    bieng
    should be being

    that they
    "that" should be "where"

    the person who know English well
    can be replaced with "knowing English well"

    & better make your decisions
    that sentence is a run on sentence because it has two topics.
    "better" doesn't belong there

    i like people here don't
    "I like how the people here don't" conveys your point better
    Last edited by ಠ_ಠ; 05-29-2009 at 08:19 AM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Understanding Memory Allocation
    By Ragsdale85 in forum C Programming
    Replies: 7
    Last Post: 10-31-2005, 08:36 AM
  2. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  3. Dynamic array allocation and reallocation
    By purple in forum C Programming
    Replies: 13
    Last Post: 08-01-2002, 11:48 AM