Click here to Skip to main content
14,425,856 members

C / C++ / MFC

 
QuestionModal vs Modeless dialog box Pin
msr_codeproject20-Jan-10 7:05
Membermsr_codeproject20-Jan-10 7:05 
AnswerRe: Modal vs Modeless dialog box Pin
Richard MacCutchan20-Jan-10 7:08
communityengineerRichard MacCutchan20-Jan-10 7:08 
AnswerRe: Modal vs Modeless dialog box Pin
Rajesh R Subramanian20-Jan-10 7:58
professionalRajesh R Subramanian20-Jan-10 7:58 
QuestionRaeding and parsing mails via POP3 Pin
VictorSotnikov20-Jan-10 5:52
MemberVictorSotnikov20-Jan-10 5:52 
AnswerRe: Raeding and parsing mails via POP3 Pin
Richard MacCutchan20-Jan-10 6:47
communityengineerRichard MacCutchan20-Jan-10 6:47 
AnswerRe: Raeding and parsing mails via POP3 Pin
Joe Woodbury20-Jan-10 10:48
professionalJoe Woodbury20-Jan-10 10:48 
AnswerRe: Raeding and parsing mails via POP3 Pin
Rozis20-Jan-10 15:06
MemberRozis20-Jan-10 15:06 
Questionproblem with stack structure implementation in C, plz help !!! Pin
hung2h20-Jan-10 4:14
Memberhung2h20-Jan-10 4:14 
#include <stdio.h>

struct Element{
	int value;
	struct Element *next;
};

struct Stack{
	int length;
	struct Element *head;
};

struct Stack createStack(){
	struct Stack s;
	s.length = 0;
	s.head = NULL;
	return s;
}


void push(struct Stack *stack, int value){
	if (stack->head == NULL){
		struct Element e = {value, NULL};
		stack->head = &e;
	}
	else{
		struct Element e = {value, stack->head};
		stack->head = &e;
		printf("(%d,%d)", stack->head->value, stack->head->next->value);
		if (stack->head == stack->head->next)
			printf("same");
	}

	stack->length++;
}

int main(){
	struct Stack s = createStack();
	int i;
	for (i = 0; i < 10; i++)
		push(&s, i);
	return 0;
}

i m really having trouble while implement stack structure in C using pointer. here the problem is only with push function, lies on 2 lines:
struct Element e = {value, stack->head};<br />
		stack->head = &e;

it seems that after i assigned stack->head to &e, the e->next(which was assigned to stack->head before) changes to be same with stack->head. lines bellow print results. can someone explain why? and how to fix it. thanks !
AnswerRe: problem with stack structure implementation in C, plz help !!! Pin
Richard MacCutchan20-Jan-10 4:38
communityengineerRichard MacCutchan20-Jan-10 4:38 
GeneralRe: problem with stack structure implementation in C, plz help !!! Pin
hung2h20-Jan-10 4:52
Memberhung2h20-Jan-10 4:52 
GeneralRe: problem with stack structure implementation in C, plz help !!! Pin
hung2h20-Jan-10 5:07
Memberhung2h20-Jan-10 5:07 
GeneralRe: problem with stack structure implementation in C, plz help !!! Pin
Tim Craig20-Jan-10 13:45
MemberTim Craig20-Jan-10 13:45 
GeneralRe: problem with stack structure implementation in C, plz help !!! Pin
hung2h20-Jan-10 18:57
Memberhung2h20-Jan-10 18:57 
QuestionPostMessage vs SendMessage Pin
Caslen20-Jan-10 3:17
MemberCaslen20-Jan-10 3:17 
AnswerRe: PostMessage vs SendMessage Pin
CPallini20-Jan-10 3:44
mveCPallini20-Jan-10 3:44 
GeneralRe: PostMessage vs SendMessage Pin
Caslen20-Jan-10 4:26
MemberCaslen20-Jan-10 4:26 
GeneralRe: PostMessage vs SendMessage Pin
CPallini20-Jan-10 4:28
mveCPallini20-Jan-10 4:28 
GeneralRe: PostMessage vs SendMessage Pin
Caslen20-Jan-10 6:12
MemberCaslen20-Jan-10 6:12 
GeneralRe: PostMessage vs SendMessage Pin
Joe Woodbury20-Jan-10 7:36
professionalJoe Woodbury20-Jan-10 7:36 
GeneralRe: PostMessage vs SendMessage Pin
Caslen20-Jan-10 10:08
MemberCaslen20-Jan-10 10:08 
GeneralRe: PostMessage vs SendMessage Pin
Joe Woodbury20-Jan-10 10:46
professionalJoe Woodbury20-Jan-10 10:46 
Questionfind folder list on a root folder Pin
Game-point20-Jan-10 2:59
MemberGame-point20-Jan-10 2:59 
QuestionRe: find folder list on a root folder Pin
David Crow20-Jan-10 3:50
MemberDavid Crow20-Jan-10 3:50 
AnswerRe: find folder list on a root folder Pin
Richard MacCutchan20-Jan-10 3:50
communityengineerRichard MacCutchan20-Jan-10 3:50 
AnswerRe: find folder list on a root folder Pin
Graham Breach20-Jan-10 3:54
MemberGraham Breach20-Jan-10 3:54 

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.