Thread: Assistance with completing a funtion.

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    Assistance with completing a funtion.

    What steps would i take to complete insertStudents and deleteStudents functions?
    I know i have to add a dummy node. Any hints at a direction would be helpful.

    Code:
    /* 
    Complete insertStudents and deleteStudents functions in the skeleton program.
    
    The output of the program should be like:
    
    sid=001,name=John
    sid=002,name=Joan
    sid=003,name=Jack
    sid=001,name=John
    sid=003,name=Jack
    */
    
    #include "ex6.h"
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    int main(){
    	Snodeptr students;
    	//Create the dummy node
    	
    	makenullStudents(&students);
    	struct studentType student1,student2,student3;
    	strcpy(student1.sid,"001");
    	strcpy(student1.sname,"John");
    	strcpy(student2.sid,"002");
    	strcpy(student2.sname,"Joan");
    	strcpy(student3.sid,"003");
    	strcpy(student3.sname,"Jack");
    	insertStudents(student1,students);
    	insertStudents(student2,students);
    	insertStudents(student3,students);
    	printStudents(students);
    	deleteStudents(student2,students);
    	printStudents(students);
    	return 0;
    }
    
    Snodeptr sAlloc(void) {
      return (Snodeptr) malloc(sizeof(struct snode));
    }
    
    void makenullStudents(Snodeptr *students) {
    	(*students)=sAlloc();
    }
    
    void insertStudents(struct studentType x, Snodeptr students) {
      
    
    
    }
    
    void deleteStudents(struct studentType x, Snodeptr students) {
    
    }
    
    void printStudents(Snodeptr students) {
    	int count=0;
    	Snodeptr p=students;
    	char ch;
    	while((p->next)!=NULL){
    		printf("sid=%s,name=%s\n",p->next->student.sid,p->next->student.sname);
    		p=p->next;
    		}
    }

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with completing this code
    By Eskimoe in forum C Programming
    Replies: 2
    Last Post: 06-10-2010, 03:47 PM
  2. Hello,i need assistance in completing the code
    By toader in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2009, 03:32 AM
  3. Replies: 2
    Last Post: 04-01-2009, 12:06 AM
  4. Completing this program
    By nesir in forum C Programming
    Replies: 2
    Last Post: 09-17-2006, 07:05 PM
  5. is this funtion ok?
    By kermit in forum C Programming
    Replies: 8
    Last Post: 08-22-2003, 05:28 PM