deleting specific numbers

This is a discussion on deleting specific numbers within the C++ Programming forums, part of the General Programming Boards category; For my final project in my C++ class we have to design a program that creates two arrays of 100 ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    Question deleting specific numbers

    For my final project in my C++ class we have to design a program that creates two arrays of 100 integers , and allows the user to append them,search,sort,insert,print,sum,mutiply and do all kinds of stuff with the arrays. it also asks us to ask the user if they want to delete specific integers from the array....i know how to design the loop and all, but my problem is this:
    do you have the compiler replace the integer to be deleted with a null character, or how would you do it?
    any and all help is appreciated, thank you!

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    it depends on the specifications of the project... but if you just mean to replace any deleted numbers with NULLs then that's what you want... if however you would like to delete it and shift all following elements over, and resize the array, that is what you would do...
    hasafraggin shizigishin oppashigger...

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    f***ing compiler

    OK so thats what i did,
    in effect i wrote a function to delete the specific integer like such:

    say i had a list of 5 numbers: 3 1 7 8 2. the user wants to delete the number 2.

    void scratch(const int a[],int size,int target)
    {
    int index=0;
    bool found=false;
    while ((!found)&&(index<size))
    if (target==a[index])
    found=true;
    else
    index++;

    if (found)
    a[index]='\0' <-------line giving me problems
    else
    cout<<"Number specified is not on the list"<<endl;
    }


    The compiler just spits more and more garbage about this. what do you think could be wrong?
    thank you!

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    instead of '\0' how about using -1 or -999 or some other number not expected in the arrray? I would be careful about putting a char into an int array as the compiler may well convert the char to it's ASCII equivalent and thereby place an unexpected but acceptable int into the array. Deletion with shifting of contents or changing int array into char array and restricting element values that way are alternatives. If negative values are allowed in the int array then I think deletion and shifting is probably the best solution.

  5. #5
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Also if you're planning on changing the contents of an array in a function, then you shouldn't pass it in as a constant.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deleting specific elements from map
    By l2u in forum C++ Programming
    Replies: 8
    Last Post: 10-07-2008, 03:00 PM
  2. Help with Rational Numbers (C++)
    By cloudjc in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2008, 05:03 PM
  3. trying to reverse numbers with sizeof operator
    By JoelearningC in forum C Programming
    Replies: 13
    Last Post: 03-09-2008, 12:53 PM
  4. Program that prints numbers in columns
    By rayrayj52 in forum C++ Programming
    Replies: 12
    Last Post: 09-20-2004, 03:43 PM
  5. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 09:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21