Click here to Skip to main content
15,920,383 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: need help with linked structs at C language Pin
Richard MacCutchan6-Jun-15 0:29
mveRichard MacCutchan6-Jun-15 0:29 
GeneralRe: need help with linked structs at C language Pin
a random user6-Jun-15 0:56
a random user6-Jun-15 0:56 
GeneralRe: need help with linked structs at C language Pin
Frankie-C6-Jun-15 6:42
Frankie-C6-Jun-15 6:42 
GeneralRe: need help with linked structs at C language Pin
a random user6-Jun-15 7:03
a random user6-Jun-15 7:03 
GeneralRe: need help with linked structs at C language Pin
Frankie-C6-Jun-15 7:12
Frankie-C6-Jun-15 7:12 
GeneralRe: need help with linked structs at C language Pin
a random user6-Jun-15 7:20
a random user6-Jun-15 7:20 
GeneralRe: need help with linked structs at C language Pin
a random user6-Jun-15 7:25
a random user6-Jun-15 7:25 
GeneralRe: need help with linked structs at C language Pin
Frankie-C7-Jun-15 5:33
Frankie-C7-Jun-15 5:33 
There are a lot of errors and redundant code.
See the following solution, study it and go on on yourself now.
C++
void deleteNode(numStruct **firstNode, numStruct *nodeToDelete)
{
	numStruct *temp = NULL;

	if (!*firstNode)
		return;	//Empty list

	// Special case the node we must delete is the first one
	if (*firstNode == nodeToDelete)
	{
		temp = *firstNode;
		*firstNode = (*firstNode)->Next;
		free(temp);
		return;
	}

	for (numStruct * currNode = *firstNode; currNode->Next; currNode = currNode->Next)
	{
		if (nodeToDelete == currNode->Next)
		{
			temp = currNode->Next;
			currNode->Next = (currNode->Next)->Next;
			free(temp);
			return;
		}
	}
}

void RemoveNodes(numStruct **anchorNode)
{
	numStruct *t = *anchorNode;
	int arr[50] = {0};
	int spot = 0;

	printf("Please enter all the numbers you want to delete and end it with - 999 \n");

	for (spot=0; spot < 50; spot++)
	{
		fflush (stdin);
		scanf("%d", &arr[spot]);
		if (arr[spot] == -999)
			break;
	}

	if (spot >= 50)
		spot--;

	for (int i = 0; i < spot; i++, t = *anchorNode)
	{
		while (t != NULL)
		{
			if (t->number == arr[i])
			{
				deleteNode(anchorNode, t);
				break;
			}
			t = t->Next;
		}
	}
}

int main(void)
{
	numStruct *anchorNode = NULL;
	numStruct *newNode = NULL;
	AddSongs(&anchorNode, newNode);
	printList(anchorNode);

	RemoveNodes(&anchorNode);
	printList(anchorNode);

	system("PAUSE");
}

GeneralRe: need help with linked structs at C language Pin
a random user7-Jun-15 6:32
a random user7-Jun-15 6:32 
GeneralRe: need help with linked structs at C language Pin
Frankie-C7-Jun-15 7:38
Frankie-C7-Jun-15 7:38 
QuestionRe: need help with linked structs at C language Pin
David Crow8-Jun-15 3:20
David Crow8-Jun-15 3:20 
AnswerRe: need help with linked structs at C language Pin
a random user21-Jun-15 9:37
a random user21-Jun-15 9:37 
QuestionThreading Issues Pin
ForNow5-Jun-15 5:09
ForNow5-Jun-15 5:09 
AnswerCAsyncSocket notifications Onconnect OnSend owned by main thread Pin
ForNow7-Jun-15 2:15
ForNow7-Jun-15 2:15 
GeneralRe: Threading Issues Pin
Albert Holguin8-Jun-15 16:21
professionalAlbert Holguin8-Jun-15 16:21 
GeneralRe: Threading Issues Pin
ForNow8-Jun-15 17:21
ForNow8-Jun-15 17:21 
Questionwhy 4 twice Pin
Member 117446405-Jun-15 4:15
Member 117446405-Jun-15 4:15 
AnswerRe: why 4 twice Pin
David Crow5-Jun-15 4:19
David Crow5-Jun-15 4:19 
AnswerRe: why 4 twice Pin
k50545-Jun-15 5:35
mvek50545-Jun-15 5:35 
AnswerRe: why 4 twice Pin
Frankie-C6-Jun-15 6:56
Frankie-C6-Jun-15 6:56 
AnswerRe: why 4 twice Pin
Daniel Pfeffer7-Jun-15 3:15
professionalDaniel Pfeffer7-Jun-15 3:15 
GeneralRe: why 4 twice Pin
Stefan_Lang11-Jun-15 3:14
Stefan_Lang11-Jun-15 3:14 
GeneralRe: why 4 twice Pin
Daniel Pfeffer11-Jun-15 3:54
professionalDaniel Pfeffer11-Jun-15 3:54 
QuestionNeed help with assembly x86 using C language Pin
a random user4-Jun-15 7:23
a random user4-Jun-15 7:23 
QuestionRe: Need help with assembly x86 using C language Pin
David Crow4-Jun-15 9:47
David Crow4-Jun-15 9:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.