Question

Name this program one.c - This program takes two command line arguments: 1. an input filename 2. a threshold Your program wil
in c prog only please!!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C PROGRAM:

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

//main
int main()
{
    //variables declaration thres for threshold value & x to read data from file
    int thres,x;

    //char type array to input file name and store
    char filename[200];
    printf("Enter the file name: ");
    scanf("%s",filename);    //filename input

    printf("Enter the threshold value: ");
    scanf("%d",&thres);      //threshold value input

    //opening and creating files
    FILE *fread;   //input file open
    fread  = fopen (filename, "r"); //here r keyword is to read from file

    FILE *feven;    //even number file
    feven  = fopen ("even.txt", "w"); //here w keyword is to write in file

    FILE *fodd;     //odd number file
    fodd  = fopen ("odd.txt", "w"); //here w keyword is to write in file

    //showing input values on screen
    printf("Input file values: ");

    //loop to read till EOF and evaluate all values from input file
    // and writing outputs in even.txt and odd.txt accordingly
    while((fscanf(fread,"%d",&x))!= EOF)  //EOF: end of file
          {
              printf("%d ",x);
              if(x>thres)  //checking threshold
              {
                  if(x%2==0)
                    fprintf(feven,"%d ",x);  //writing in even.txt
                  else
                    fprintf(fodd,"%d ",x);   //writing in odd.txt
              }
          }

          //closing all files
          fclose(fread);
          fclose(feven);
          fclose(fodd);

    printf("\n\n");


    return 0;
}

OUTPUT:

3 X C:\Users\NITISH\Music\BooleanDecision\main.exe Enter the file name: input.txt Enter the threshold value: 5 Input file val

INPUT FILE:

input - Notepad File Edit Format View Help ||| 12 5 7 9 3 10 4

even.txt file created:

even - Notepad File Edit Format View Help 12 10

odd.txt file created:

odd - Notepad File Edit Format View Help 19

Add a comment
Know the answer?
Add Answer to:
in c prog only please!! Name this program one.c - This program takes two command line...
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
  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • In C please Create a program that takes two integers as command line arguments (num, length)...

    In C please Create a program that takes two integers as command line arguments (num, length) and outputs a list of the first length multiples of num. num should be included in the returned array. For example: ./a.out 7 5 -> [7, 14, 21, 28, 35] ./a.out 12, 10 -> [12, 24, 36, 48, 60, 72, 84, 96, 108, 120] ./a.out 17, 6 -> [17, 34, 51, 68, 85, 102] Ma Word starts with a vowel add "yay" to the...

  • Modify When executing on the command line having only this program name, the program will accept...

    Modify When executing on the command line having only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with your new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the command line to be tested...

  • 2. Write a function file_copy() that takes two string parameters: in file and out_file and copies...

    2. Write a function file_copy() that takes two string parameters: in file and out_file and copies the contents of in_file into out file. Assume that in_file exists before file_copy is called. For example, the following would be correct input and output. 1 >>> file_copy( created equal.txt', 'copy.txt) 2 >>> open fopen ( copy.txt') 3 >>> equal-f = open( 'created-equal . txt') 4 >>equal_f.read () 5 'We hold these truths to be self-evident, Inthat all men are created equalIn' 3. Write:...

  • Write a C program that reads a list of positive integers from a file named "input.txt."...

    Write a C program that reads a list of positive integers from a file named "input.txt." and count number of odd integers and even integers and prints the results to another file called "results.txt". Please submit both the input and results files along with the c program.

  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...

  • Help please Write a program named one.c that takes a single command-line argument, the name of...

    Help please Write a program named one.c that takes a single command-line argument, the name of a file. Your program should read all the strings (tokens) from this file and write all the strings that are potentially legal words (the string contains only upper-case and lower-case characters in any combination) to the file words. Your program should ignore everything else (do not write those strings anywhere 1. As an example, running /a.out dsia would result in the generation of the...

  • C Language Programming. Using the program below - When executing on the command line only this...

    C Language Programming. Using the program below - When executing on the command line only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the...

  • In c language. I have to read 3 files and used the numbers in the file...

    In c language. I have to read 3 files and used the numbers in the file in a program. An example of the 3 files are below. How do read the numbers, I realize it’s with arrays. The input won’t have more than 100 lines but it can have less n 3. Input Files The filename includes the variable name and the sensor number as: variable name <sensor id txt For example "BT 0001.txt" is the file that contains the...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

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