Answer to Question #249517 in C for Vish....

Question #249517
In the situation where there are multiple users or a networked computer system, you probably share a printer with other users. When you request to print a file, your request is added to the print buffer. When your request reaches the front of the print buffer, your file is printed. This ensures that only one person at a time has access to the printer and that this access is given on a first-come, first-served basis. Write a C program to implement the above scenario.
1
Expert's answer
2021-10-11T02:56:51-0400


#include <stdio.h>
#include <stdlib.h>
 


struct Node
{
  int item;
  struct Node *nextNode;
};
 


void add_to_printBuffer(struct Node** head, int item)
{
    
    struct Node* node = (struct Node*) malloc(sizeof(struct Node));
 
    
    node->item  = item;
 
   
    node->nextNode = (*head);
 
    
    (*head)    = node;
}
 


void printList(struct Node *node)
{
	struct Node* last = NULL;
  while (node != NULL)
  {
     


	 add_to_printBuffer(&last, node->item);
     node = node->nextNode;
  }
  while(last !=NULL){
  	printf(" %d", last->item);
  	last = last ->nextNode;
  }
  
}
 


int main()
{


  struct Node* node = NULL;
 




  add_to_printBuffer(&node, 7);
 
  
  add_to_printBuffer(&node, 1);
 
  
 
 
  
 
  printf("\n Files to br printed: ");
  printList(node);
 
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS