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
  • 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

  • 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...

  • Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusi...

    Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string (‘A’<->’Z’, ‘B’<->’Y’, ‘C’<->’X’, etc). You should divide this conversion task among the n threads as evenly as possible. Print out the string both before...

  • All commands must be in the command line. The expense data file is separate. Programming Project...

    All commands must be in the command line. The expense data file is separate. Programming Project #2: Manage Spending Using Commands Objectives: • Understand how to create and manipulate list of objects using array or vector class • Handle input errors and invalid values • Design and create a well-structure program using C++ basic programming constructs and classes. Description: Each “expense” contains 2 values: the spending amount (double) and its description (string) Here is an example of the “expense” data...

  • Write a C program, named sortit, that reads three integers from the command line argument and...

    Write a C program, named sortit, that reads three integers from the command line argument and returns the sorted list of the integers on the standard output screen, For instance, >sortit 3 5 7 >The sorted list is 3, 5, 7. >sortit 4 0 9 >The sorted list is 0, 4, 9 >sortit 1 p 9 >sortit: invalid input p. >sortit >usage: sortit num1 num2 num3! 1. The source code of a c file 2. Screenshots that show successful execution...

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
ADVERTISEMENT