292PracticeFinalFA09

292PracticeFinalFA09 - CSC292 Practice Final Exam 1 What...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC292 Practice Final Exam 1. What does the following function doit appear to be doing? 2. This function is suffering from a problem called a memory leak . How should it be fixed? struct quiz { int x struct quiz *prev; struct quiz *next; } QUIZ; void doit( QUIZ **head, int x ) { QUIZ *p = *head; while ( p != NULL && p->x != x ) p = p->next; if ( p != NULL ) { if ( p == *head ) { if ( p->next == NULL ) *head = NULL; else { *head = p->next; p->next->prev = NULL; } } else if ( p->next == NULL ) { p->prev->next = NULL; } else { p->next->prev = p->prev; p->prev->next = p->next; } } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3. The following program is supposed count the number of lines in a file. In the code, a call to the function count_lines is shown. Using the information given by the surrounding code, write the function prototype and the function declaration and body for the function count_lines. #include <stdio.h> /* Write the function prototype here */ int main( int argc, char *argv[] ) { int n = 0; if ( argc != 2 ) { printf( “Usage: linecount filename\n” );
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/11/2009 for the course MTH 531 taught by Professor Rthi during the Spring '09 term at Norfolk.

Page1 / 6

292PracticeFinalFA09 - CSC292 Practice Final Exam 1 What...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online