![]() |
| | #1 |
| Registered User Join Date: Jul 2005
Posts: 10
| Deleting element from an array problem I am trying to remove a user specified element from the display of an array. I know that this doesn't take it out of the array, but I figure that if I get this it would be the same process copying it to a temp array and then back. Code:
printf("Please enter number to delete");
scanf("%d",&d);
printf("\n\n\nModified list:");
for (i=0;i<x;i++)
{
if (i = d)
{
i = i+1;
}
else
{
printf("%s",words[i]);
}
}
|
| xamlit is offline | |
| | #2 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,710
| > if (i = d) Perhaps == instead of = Didn't your compiler warn you? Are you using a compiler which is capable of warning you? |
| Salem is offline | |
| | #3 |
| Registered User Join Date: Nov 2004 Location: india
Posts: 493
| You need not start from 0, if the user inputs the number into the variable d, just start out with that number itself. Code: for(i=d;i<MAX-1;i++) array[i]=array[i+1]; |
| PING is offline | |
| | #4 | |
| Registered User Join Date: Jul 2005
Posts: 10
| Quote:
Hmm.. but doesn't that just start from the element they entered? I want to be able to display all the elements as if it were removed. such as : 1.box 2.shoe 3.red 4.crayon user selects to delete red from the display, new display should look like this: 1.box. 2.shoe 3.crayon I hope I'm making this clear enough. I appreciate any help you give me. | |
| xamlit is offline | |
| | #5 |
| Registered User Join Date: Nov 2004 Location: india
Posts: 493
| just replace this Code: array[i]=array[i+1]; Code: strcpy(array[i],array[i+1]); |
| PING is offline | |
| | #6 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| And you should set array[0] to something, too. Code: if (i = d) Code: if (i == d)
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. |
| dwks is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with Dynamically Increasing Array of Integers | laserlight | C++ Programming | 30 | 07-04-2008 07:27 AM |
| Array problem | TomBoyRacer | C++ Programming | 3 | 04-08-2007 11:35 AM |
| simple array of char array problem | cloudy | C++ Programming | 5 | 09-10-2006 12:04 PM |
| question about multidimensional arrays | richdb | C Programming | 22 | 02-26-2006 09:51 AM |
| Problem deleting dynamic array | pliang | C++ Programming | 7 | 04-11-2005 04:07 PM |