Question

In C write a program that must accept one argument from the command line. The argument...

In C write a program that must accept one argument from the command line. The argument is the name of the file containing the processes (for example: processes.csv).This file is comma-separated with three columns (process ID, arrival time and burst time) with each row for an individual process. You can assume that this file will have a maximum of 10 processes.

For example

Input: processes.csv

ProcessID,Arrival Time,Burst Time

0,1,3
1,0,5
2,9,8

3,10,6

Where the first element is processes, the second is Arrival time and the third is Burst time. Store each in separate arrays (one for processes, one for arrival and one for burst)

Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code in image:

1 #includec stdio.h> 2 #include<string.h> 3 #include«ctype.h> 4 int main) lincluding pacakages FILE *fp1; char file_name[100]43 printf(process id,arrival id,burst time\n) for(i:0; İs(length/3) ;i++){ 45 46 47 48 49 50 51 //printing every number pri

The code in the text:

#include<stdio.h> //including pacakages
#include<string.h>
#include<ctype.h>
int main() {
   FILE *fp1;
   char file_name[100],c; //declaration of characters
  
   printf("Enter name of the file: ");
   scanf(" %s",file_name); //taking file name
  
   fp1=fopen(file_name,"r"); //opening the file
  
   int list[30],process_id[10],Arrival_time[10],Burst_time[10],len; //decalring list
  
   c=fgetc(fp1); //taking character from fp1 pointer or file
   int i=0,number,num=0;
   while(c!='\n'){ //iterating until it hits a newline
       c=fgetc(fp1);
   }
   c=fgetc(fp1);   
  
   while(c!=EOF){ //iterate until end of file
       if (isdigit(c)){ //if it is digit
           sscanf(&c,"%d",&number); //changing character to number (c)
           num=(num*10)+number; //if it has more than 1 digit..ex:-12== 0*10+1=1 , 1*10+2=12
       }
       else if (c==',' || c=='\n') { //if it is new line or , then it will store the number in list
           list[i]=num;
           num=0;
           i++;
       }
       c=fgetc(fp1);
   }
   int j=0,length=i+1;
  
   for(i=0;i<length;i++){ //iterating through each numbre storing it in corresponding lists
       process_id[j]=list[i]; //adding numbers into lists using indices
       Arrival_time[j]=list[i+1];
       Burst_time[j]=list[i+2];
       i=i+2;
       j++;
   }
  
   printf("process id,arrival id,burst time\n");
   for(i=0;i<(length/3);i++){   
       printf("%d, ",process_id[i]); //printing every number
       printf("%d, ",Arrival_time[i]);
       printf("%d\n",Burst_time[i]);
   }
   return 0;
}

Output:

jack@jack-TravelMate-P243-M:~$ ./a.out Enter nane of the file: processes.csv process id,arrival id,burst tine 0, 1, 3 11, θ,

Add a comment
Know the answer?
Add Answer to:
In C write a program that must accept one argument from the command line. The argument...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is a C program question you will implement a program to show the performance of...

    This is a C program question you will implement a program to show the performance of FCFS scheduling algorithm with I/O burst. Your program should get a file (e.g., “jobs.txt”) as the command-line input, and read the contents of the file. This file contains a set of processes. For example, consider the file with the following content: 1:(45,15);(16,20);(80,10);(40,-1) 2:(15,10);(60,15);(90,10);(85,20);(20,-1) 3:(30,15);(40,20);(5,15);(10,15);(15,-1) In this example we have 3 processes, each process is represented in a separate line. The general format of a...

  • Write a C program called test that takes one command line argument, an integer N. When...

    Write a C program called test that takes one command line argument, an integer N. When we run test: ./test N the program will do this: the parent process forks N child processes each child process prints its process ID, exits the parent process waits for all child processes to exit, then exits

  • Command line input In C++ it is possible to accept command line arguments. Command-line arguments are...

    Command line input In C++ it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like Linux and are passed in to the program from the operating system. To use command line arguments in the program, it must first understand the full declaration of the main function, which until now has accepted no arguments. In fact, main can accept two arguments: one argument is number of command line...

  • Write a program in C that accepts a port number as a command line argument, and...

    Write a program in C that accepts a port number as a command line argument, and starts an HTTP server. This server should constantly accept() connections, read requests of the form GET /path HTTP/1.1\r\n\r\n read the file indicated by /path, and send it over the "connect" file descriptor returned by the call to accept().

  • Please I need help with this problem Write a c++ program that will accept the names...

    Please I need help with this problem Write a c++ program that will accept the names of 3 processes as command-line arguments. Each of these processes will run for as many seconds as (PID%10)*3+5 and terminate. After those 3 children terminated, the parent process will reschedule each child. When all children have been rescheduled 3 times, the parent will terminate. Each child must print out its process id every time it runs.

  • Part 1: Write a C program that takes an integer command line argument n, spawns n...

    Part 1: Write a C program that takes an integer command line argument n, spawns n processes that will each generate a random numbers between -100 and 100, and then computes and prints out the sum of these random numbers. Each process needs to print out the random number it generates. name the program 003_2.c

  • This program will reinforce our knowledge on basic ‘C’ program control, arrays, and editing and compiling...

    This program will reinforce our knowledge on basic ‘C’ program control, arrays, and editing and compiling ‘C’ programs. The objective of this assignment is to create a program that tallies a shopping list of items and displays each selected item, item cost, and total cost of all the selected items plus tax. The program will setup a simple sporting goods store with a few items and prices. The user will submit a shopping list in a textfile and submit it...

  • C program that converts digits into word form. It should accept one command line argument, which...

    C program that converts digits into word form. It should accept one command line argument, which is an integer in the range from -2147483648 to 2147483647. (This is the valid range of 32-bit values in C language.) The program will convert the given number into english words and display the answer exactly as in the shown below: This is C language only, Im having trouble getting passed 1 million and need help badly! thank you. zero one hundred and twenty-three...

  • Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the...

    Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the fork function to produce two processes. In the child process print out the lower case version of the string. In the parent process print out the reversed upper case version of the string (e.g. child: “abc”; parent: ”CBA”). You may call the toupper and tolower functions in the header <ctype.h> if you wish. Specify in the output whether the parent or child process is...

  • Write a program mexp that multiplies a square matrix by itself a specified number of times、mexp...

    Write a program mexp that multiplies a square matrix by itself a specified number of times、mexp takes a single argument, which is the path to a file containing a square (k × k) matrix M and a non-negative exponent n. It computes M and prints the result Note that the size of the matrix is not known statically. You ust use malloc to allocate space for the matrix once you obtain its size from the input file. Tocompute M". it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT