You have some uninitialised variables in swapLines(). (Did your compiler warn you about that?)
That's not the only problem in this function; p->prev->next=p2->next->prev; p2=p->prev->next; doesn't seem sufficient to swap two lines over. Consider the case [a]<->[p]<->[b]<->[p2]<->[c], endpoint cases NULL<-[p]<->[b]<->[p2]<->[c] and [a]<->[p]<->[b]<->[p2]->NULL and p2>p [a]<->[p2]<->[b]<->[p]<->[c]. Work out on paper what pointers need updating in each case.

insertLine won't work at all; have a close look at char newline; scanf("%s", &newline); char newline defines newline to be a single character; if you try to copy a string into it you'll corrupt your stack.

insertNode() has a number of bugs; what about p->prev; if inserting at the top; why "t=r;" as it's a doubly-linked list - just use r->prev if you want the previous node; you don't check line_no against c; what about r->prev (which points at old t instead of tempo...by the way...t = tempo = great way of confusing yourself, not to mention the constant use of meaningless variable names. Wouldn't it be a lot clearer if the code said nodeBefore->next=newNode; newNode->next=nodeAfter; newNode->prev=nodeBefore; nodeAfter->prev=newNode;) and t(was tempo)->prev. Again you can solve a lot of this by working it out on paper and comparing it with the code.

The rest of the code seems to suffer from duplicates of the above comments. DON'T use global temporary variables (p). DO use meaningful variable names. DO work it out on paper.

Last edited by xpi0t0s; 26Aug2008 at 20:46..