Page 1 of 2 12 LastLast
Results 1 to 40 of 59

Thread: Help on Pointers project Please!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143

    Question Help on Pointers project Please!

    I have this project to do and I have no idea where to even start let alone do the dang thing. Heres the project:

    Objective: This program will consist of creating a program that will accept a list of integers from the user, perform operations on the list and return results to the user

    Specifics: The program should initially ask the user for a list of integers. The program should continuously request integers until the user inputs a negative number. Once the list is read in, the program should then present the user with a list of options. The options should include: input a new list, display the maximum, display the minimum, display the average, display the median, and exit. Once an operation is performed, the menu should be redisplayed.

    Requirements:
    • The integers must be stored in a dynamic array, which is initially 10 items in size and doubles each time more space is needed
    • The menu must be implemented with a switch statement; use default condition to handle menu error checking
    • Each case of the switch statement, except default, must call a function to process the operation
    • All function definitions must be placed after main, through the use of prototypes
    • Do not use global variables



    OMG, this thing is like impossible.
    Last edited by chugger93; Oct 1st, 2002 at 10:17 AM.

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Why don't you start doing it first and ask us the parts which you are stuck?

    Don't try to code everything in one go(, it is hard to visualise). Do it progressively. After you have made the first part working, then proceed on to code the next part.

    I have a similar program like this, but I'm not going to give it to you because you will not learn anything out of it. Try doing it yourself.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    I dunno even where to start man! Its my friggin 2nd week in C++, teacher goes way to fast. I dunt even really like C++, I just need to pass the class to get my degree


  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Then ask the instructor for help. Most will be more then willing to give you some time if you dont understand something.

    Z.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    can anyone at least get me started?

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Take a look at the vector template, www.cplusplus.com should have some information on that. Play around with it for a while, then see how you go...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    This reads them in - but no teacher whio can actually code will believe this is your code Fair warning.

    Use *base and current to print the numbers back to the user.
    I may have made a mistake or three, but you get to fix it.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define zout(c) memset(c,0x00,sizeof(c))
    static int *array,*base;
    static size_t arrlen=5;
    void more(int);
    int main(){
         int current=0;  /* counter for the number of integers in the array */
         const char *prompt="Enter a number, <RETURN> to quit: ";
         char tmp[20]; /* storage for input */
         zout(tmp); /* zero the string */
         array=(int *)malloc(sizeof(int)*arrlen); /* create half-size array */
         more(current);   /*bld the array to start with*/
         for(printf(prompt);*gets(tmp);current++,array++){ 
              if(!current%10)more(current);
              *array=atoi(tmp);
              zout(tmp);
    	  printf(prompt);
         }
         return 0;
    }
    
    void more(int offset){
          arrlen*=2; /* array doubles in size each time */
          base=realloc(array,arrlen*sizeof(int)); /* set the beginning of the array */
          array=base;
          if(array){
    	 if(offset){
               offset++;
    	   while(offset--) array++; /* reposition the active pointer */
    	   }
          }else{
               perror("Unable to allocate more memory");
               exit(EXIT_FAILURE);
           }
          return;
    }

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Ouch
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    I cant use a vector dude, he'll wonder about how im knowing about it.

    and Jim, *** is that code? Thats like really advanced I think for this assignment...isnt their a less complicated way?!

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Well, he can come here and get the same response.

    It's the best way, in C++, and therefore is the way that should be taught.


    Jim...you're a professional -- would you say that they should use pointers, or use the vector first, and *then* learn how it works inside?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Beautiful code, jim =.). Though no globals.

    parksie: vector first, then linked lists, and then make them write a vector. So you get basic pointers, and then array like pointers.

    chugger: You could write the code with a vector, debug it, and such, and then re-write the code using a pointer instead of a vector.

    Z.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    WEll, mabe we dont have to use it with a pointer, it doesnt say that anywhere in the assignment anywhere. I just know we havnt gone over what a vector is. But who knows, mabe today he will, so how do u do it with a vector. or at least start it

  13. #13
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Parksie - learning C++ was hard for me because I had used C too long. And I do not use C++ very often. Which also doesn't help.

    A new person is better off learning C++ and the STL and programming at that level as much as possible. IMO.

    He should use vectors for the project - except I don't know how to double a vector's storage, and that seems to be a requirement.
    I think the teacher wanted heap pointers.

    Probably should not have posted the code written that way.
    Usually, it's a bad idea because beginners can't read it. But at least I was sure it wouldn't end up verbatim in his/her homework project. And pass as his own code. I really don't mind showing how, but doing someone else's homework isn't even remotely ethical.

    Last edited by jim mcnamara; Sep 19th, 2002 at 05:14 PM.

  14. #14
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    vector doubling is easy... =).
    Code:
    vec.resize(vec.size()*2);
    This teacher seems a bit whacked out to me... o.o;

    Z.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    cant use vectors, gotta use pointers he said

  16. #16
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Shoot him, and give parksie his job =).

    Z.

  17. #17
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I'll bloody shoot him, and give a trained monkey his job!

    Blimey, no wonder professional programmers are so bad
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    ya but i guess it can be done

  19. #19
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Try a struct with 3 members, a pointer to the start of your memory block, a count of the number of elements you've allocated, and a count of the number that are actually *used*.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  20. #20
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Originally posted by parksie
    Blimey, no wonder professional programmers are so bad
    I wouldnt say that =). Though it really makes you wonder. I guess you can really tell the difference between those for whom coding is a passion, and those who do it for a living in the quality of the work...

    Z.

  21. #21
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    We don't hire programmers right out of university. Period. Too often it doesn't work out.

    For example, up until 1995, UNM was producing CS students who had only used Amigas. Had no unix, VMS, MVS, or Windows. Insane. IMO.

  22. #22
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    How much actual experience, jim? Does it have to be actual, on-the-job stuff, or can it be side projects, and such?

    Z.

  23. #23
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    ***?!??

    This is not too hard of a project, its a dynamic array:

    PHP Code:
    int dynarray = new int [size]; 
    And it doubles everytime you need more space? Say you start with 10, just size*2 it every time! Thats all...

    You have a class,

    MyArrayClass with the members: int count, int size, int * dynarray

    Thats all.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    well, i got this so far.

    int main(int argc, char* argv[])
    {

    int *ptr;
    ptr = new int[10];
    int max_array = 10;
    int count = 0;


    cout << "Enter A List Of Integers: ";
    cin >> max_array[count];

    while(true)
    {
    if(max_array == count)
    expand(&ptr,max_array);
    ptr[count++];
    }



    void expand(int **ptr, int &max_array)
    {
    int *temp;
    temp = new int[3*max_array];
    for(int i=0;i<max_array;i++)
    temp[i] = *(*ptr+i); //Changed
    delete [] *ptr;
    *ptr = temp;
    max_array *= 3;
    }





    Im still lost though, My code is probaly way off. I will pay someone for the code!, lol uggg im soo confused
    Last edited by chugger93; Sep 30th, 2002 at 09:36 AM.

  25. #25
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    boooooooooooo, what you really need is to learn the language so that you dont make careless mistakes. Your code doesnt make sense what so ever!!! What EXACTLY are you tring to do?

    Here is a few tips i gotta give you:
    PHP Code:
    int main(int argccharargv[])
    {

    int *ptr;
    ptr = new int[10]; // always check the return of new != NULL
    int max_array 10;
    int count 0;


    cout << "Enter A List Of Integers: ";
    cin >> [color=red]ptr[count];[/color// the aray is called ptr
    // max_array is only the "count" - a number

    while(true// i see an infinite looop here
    {
    if(
    max_array == count// this doesnt make sense? why?
    expand(&ptr,max_array); // what you trying to do again
    ptr[count++]; // this line doesnt make sense
    }


    // obviously this function was not written by you.. whatever 
    // the case maybe, i dont understand what it tries to do... there
    // is no user input in your while loop, so nothing will happen

    void expand(int **ptrint &max_array)
    {
    int *temp;
    temp = new int[3*max_array]; // check if (temp != NULL)
    for(int i=0;i<max_array;i++)
    temp[i] = *(*ptr+i); //Changed
    delete [] *ptr// set ptr =0
    *ptr temp;
    max_array *= 3;

    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  26. #26

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    read my very 1st post, thats what im tryin to do

    this is the original code, our teacher gave us to get us started using File I/O, but i dunno how to convert it to our assignment

    using namespace std;

    void expand(int**,int&);

    int _tmain(int argc, _TCHAR* argv[])
    {
    ifstream infile("data.in");
    ofstream outfile("data.out");
    int *ptr;
    ptr = new int[10];
    int max_array = 10;
    int count = 0;
    while(!infile.eof())
    {
    if(max_array == count)
    expand(&ptr,max_array);
    infile >> ptr[count++];
    }
    infile.close();
    //Added: a version of Bubble Sort
    for(int i=0;i<count;i++)
    {
    int min = i;
    for(int j=i+1;j<count;j++)
    if(ptr[j]<ptr[min])
    min = j;
    int temp = ptr[i];
    ptr[i] = ptr[min];
    ptr[min] = temp;
    }
    for(int i=0;i<count;i++)
    outfile << ptr[i] << endl;
    outfile.close();
    return 0;
    }

    void expand(int **ptr, int &max_array)
    {
    int *temp;
    temp = new int[3*max_array];
    for(int i=0;i<max_array;i++)
    temp[i] = *(*ptr+i); //Changed
    delete [] *ptr;
    *ptr = temp;
    max_array *= 3;
    }

  27. #27
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Oh dear Jesus! He teaches _TCHAR, and not vector?!

    *dies*

    Z.

  28. #28
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Quite confusing what your teacher gave you.

    e.g. you have one function taking to parameters by reference. Yet one paramter is passed in the C-by-ref style (as pointer) and one in the C++ style (as a real reference).

    But basically....
    Just replace infile with cin, outfile with cout, change the loop condition to a test whether the user entered a negative number and modify the expand function so that it only doubles the array size instead of tripling.

    Next put the input request into a seperate function. Write additional functions that do the computations and output the results.

    Then fill the main function with the menu. If you browse this forum a little you'll find examples of how to do this, e.g. the "Input Valid Data" thread on this page.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    I keep getting this error msg

    C:\Program Files\Microsoft Visual Studio\assign3\assign3.cpp(34) : error C2601: 'expand' : local function definitions are illegal

    whenever i try to compile ?

  30. #30
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Sounds like a missing closing brace ( } )
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  31. #31

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    Ok, I just need help on making a function that reads in the integers and once the integers are read in, will present the user with the list of options.

    I can do the switch statement, or case statement, Im just not sure how to make a function that reads the integers in, or where to put it.

    heres my code so far

    using namespace std;

    void expand(int**,int&);


    int main(int argc, char* argv[])
    {

    int *ptr;
    ptr = new int[10];
    int max_array = 10;
    int count = 0;
    while(!cin.eof())
    {
    cout << "enter";
    cin >> count;
    if(max_array == count)
    expand(&ptr,max_array);
    cin >> ptr[count++];

    }

    return 0;
    }


    void expand(int **ptr, int &max_array)
    {
    int *temp;
    temp = new int[2*max_array];
    for(int i=0;i<max_array;i++)
    temp[i] = *(*ptr+i); //Changed
    delete [] *ptr;
    *ptr = temp;
    max_array *= 2;
    Last edited by chugger93; Sep 30th, 2002 at 01:29 PM.

  32. #32
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    cin won't ever have a eof condition unless the user figures out how to input an EOF character.

    The loop condition must be a test for a negative number! It is explicitly stated in your requirements.

    And a do...while loop would fit better here (unless you feel uncomfortable with it).

    Then you should output a newline or at least whitespace together with the "enter".

    The code for entering numbers should be in a seperate function as it may be called from the menu,

    As for menus I already told you: browse the forum.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  33. #33
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by CornedBee
    cin won't ever have a eof condition unless the user figures out how to input an EOF character.
    Any user worth anything should know how to signal EOF anyway.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  34. #34
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yeah, sure.


    Ctrl+Z is the DOS way, but last time I tried it it didn't work...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  35. #35

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    I dont see why someone cant get me started here with some of this code. I seriosuly just dont understand this language. I suck at all programming languages. I dont wanna fail the course. Im gonna look like a dope if I keep asking my teacher for help. I try and study this material, it just doesnt sink in. I cant grasp the dam concept.

  36. #36

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    how do u call a function ? isnt it function_name();

    ?


    its not workin like that


    Plus I cant get this to compile so far...



    #include "stdafx.h"
    #include <iostream>
    #include <fstream>

    int request();

    using namespace std;

    void expand(int&);
    void request(int&, int&);



    int main(int argc, char* argv[])
    {


    int *ptr;
    ptr = new int[10];
    int max_array = 10;
    int count = 0;


    request();








    void expand(int &max_array)
    {
    int *temp;
    temp = new int[2*max_array];
    for(int i=0;i<max_array;i++)
    temp[i] = ptr[i];
    delete [] ptr;
    ptr = temp;
    max_array *= 2;
    }

    void request(int &count, int &max_array)
    {
    count = 0;
    int integer;

    while(true)

    cout << "Enter An Integer: ";
    cin >> integer;

    for(integer<0)
    return;
    if(count == max_array)
    expand()

    ptr(count++) = integer
    }



    return 0;
    }


    the error msg's are C:\Program Files\Microsoft Visual Studio\assign3\assign3.cpp(37) : error C2601: 'expand' : local function definitions are illegal
    C:\Program Files\Microsoft Visual Studio\assign3\assign3.cpp(48) : error C2601: 'request' : local function definitions are illegal
    Error executing cl.exe.

    assign3.obj - 2 error(s), 0 warning(s)
    Last edited by chugger93; Oct 1st, 2002 at 09:06 PM.

  37. #37
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Sorry man, you are so lost, its not even funny!

    Do it like this:

    1. Call the input function
    2. Call the menu function
    3. Process the menu results
    4. Repeat steps 2 and 3 untill exit

    Here is a starting point,

    PHP Code:

    // the includes
    #include <iostream>
    using namespace std;

    // Expand the array
    void expand(int **ptrint max_array);

    // reset the list data
    void reset (int ** ptrint countint max_array);

    // Get the input
    void inputdata (int ** ptrint countint max_count);
    int request ();

    // Get the menu
    int menu ();

    // Get Min, Max, Mean, etc (you need to make these)
    int GetMin (int ptrint count);
    int GetMax (int ptrint count);
    float GetMean (int ptrint count);

    int main (void)
    {
        
    int ptr 0;
        
    int count 0;
        
    int max_array 10;
        
    int temp 0;

        
    // create the initial list
        
    ptr = new int [max_array];

        
    // call the input numbers function
        
    inputdata (&ptr, &count, &max_array);

        
    // Now start the menu sequence
        
    do {
            
    temp menu ();
            
    swicth (temp)
            {
                case 
    0:
                    
    // exit
                    
    break;

                
    // number 1 on the menu was pressed
                
    case 1:
                    
    reset (&ptr, &count, &max_array);
                    
    inputdata (&ptr, &count, &max_array);
                    break;
                    
                
    // case 2, 3, 4, etc...
                
                // default (anything not covered by case n)
                
    default:
                    
    cout << temp << " is invalid!" << endl;
            }
        } while (
    temp != 0);

        
    // the loop has been exited
        
    return 0;
    }

    void expand(int **ptrint max_array)
    {
        
    int *temp;
        
    int i;
        
        
    temp = new int[* (*max_array)];
        for(
    0< *max_arrayi++)
        {
            
    temp[i] = *(*ptr+i); //Changed
        
    }
        
        
    delete [] *ptr;
        *
    ptr temp;
        
    max_array *= 2;
    }

    void reset (int ** ptrint countint max_count)
    {
        
    delete [] *ptr;
        *
    max_count 10;
        *
    count 0;
        *
    ptr = new int [*max_count];
    }

    void inputdata (int ** ptrint countint max_count)
    {
        
    int temp 0;
        
        
    // start inputing numbers
        
    do {
            
    temp request ();

            
    // negative number exits the loop
            
    if (temp 0) {
              break;
            }

            
    // expand the list if it gets too small
            
    if (*count >= *max_count)
                
    expand (ptrmax_count);

            
    // now add this number to your list
            
    (*ptr)[*count] = temp;
            (*
    count)++;

        } while (
    true);
    }

    int request ()
    {
        
    // Get an integer and return it
        
    int integer;
        
    cout << "Enter An Integer: ";
        
    cin >> integer;
        
    cin.ignore ();

        return 
    integer;
    }

    int menu ()
    {
        
    int item;
        
    // Display menu and return input

        
    cout << "===============================" << endl;
        
    cout << "      The Cool Menu            " << endl << endl;
        
    cout << " 0. Exit" << endl;
        
    cout << " 1. Enter List" << endl;
        
    // ... bla bla bla
        
        
    cin >> item;
        
    cin.ignore ();

        
    // return item
        
    return item;
    }

    // example of max function, use this to do the others (min, mean, bla)
    int GetMin (int ptrint count)
    {
        
    int max ptr[0];
        for (
    int i 0counti++)
        {
            if (
    max ptr[i])
            {
                 
    max ptr[i];
            }
        }

        return 
    max;

    There it is, a (almost complete) starting point, I hope now I shed light on you (cuz if i do anymore, i might as well turn it in with my name on it ).
    Last edited by MoMad; Oct 2nd, 2002 at 03:00 AM.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  38. #38
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    BTW: you cannot have ANY functions inside another function, main is a function, so thats why you got those errors.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  39. #39
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I suppose this was necessary. Thanks MoMad, else I would have got to do such a thing...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  40. #40

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    Momad: thanx!!

    but the hell does this mean?

    void expand(int **ptr, int * max_array)
    {
    int *temp;
    int i;

    temp = new int[2 * (*max_array)];
    for(i = 0; i < *max_array; i++)

    temp[i] = *(*ptr+i); //Changed


    delete [] *ptr;
    *ptr = temp;
    max_array *= 2;
    }


    C:\Program Files\Microsoft Visual Studio\assign3\assign3.cpp(81) : error C2296: '*=' : illegal, left operand has type 'int *'


    and it points to max_array **=2;


    im gonna try this code, there are some differences, but im gonan try to see what u mean

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width