Question

Write a c program that takes in a text file and writes lines with only lowercase...

Write a c program that takes in a text file and writes lines with only lowercase letters to another text file which is disclosed from the command line. If no text file to output to is disclosed in the command line, the lines with only lowercase letters should be written into a text file called "all_lower.txt"

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

CODE ::

EXECUTION ::

RAW CODE :

#include <stdio.h>
#include <stdlib.h>
int main(int argc,char* argv[]){
   char str[2];
   if ( argc != 2 ){   // Checking the Command line Args
       printf("Usage : ./executable <Text file Name>\n");
       exit(0);
   }
   FILE *fp = fopen(argv[1], "r");
   FILE *new= fopen("all_lower.txt","w");
   if (fp == NULL){    // On Error means , File not Found
puts("File not Found!.....");
exit(0);    // Exiting  
}
// If File is there , WE read its chars one by one , Write them to new file
// BY converting Them to lower case
while (fgets(str,2, fp) != NULL){   // Read a single char, 2nd char is '\0'
   // Condition for the lower case are [ 65 - 90 ] <- Ascii values
   // Difference between the Upper and Lower is 32
   // Means lower + 32 -> Upper
if (65 <= str[0] && str[0] <= 90) str[0] += 32;
fprintf (new, str);   // Wtiting the Updated Char into the File
}
// Closing The files
fclose(fp);  
fclose(new);
}

Add a comment
Know the answer?
Add Answer to:
Write a c program that takes in a text file and writes lines with only lowercase...
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 last10 that prints the last ten lines of a text file....

    Write a C program called last10 that prints the last ten lines of a text file. The program can be used from the command line with: last10 filename or last10 If there is no filename, last10 processes standard input.

  • Part I) Write a program that copies one file to another, replacing all lowercase characters with...

    Part I) Write a program that copies one file to another, replacing all lowercase characters with their uppercase equivalents. Part II) Write a program that merges lines alternately from two files and writes the results to a third file. If one file has less lines than the other, then the remaining lines from the larger file should be printed to the screen. Using C language

  • In c programming, I need to write a program that reverses each of the lines in...

    In c programming, I need to write a program that reverses each of the lines in a file. The program accepts two command line arguments: The first one is the name of the input file The second is the name of the output file If the user didn't give two filenames, display an error message and exit. The program reads in each line of the input file and writes each line in reverse to the output file. Note, the lines...

  • Write a program that inputs a text file. The program should print the unique words in...

    Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Note: The sort function sorts first numbers, then capital letters, then lowercase letters. That is fine for this assignment as you can see from the sample output. But even if the same word appears multiple times in the file it should only be displayed once in the output. (python)

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • FOR JAVA Write a program that takes two command line arguments: an input file and an...

    FOR JAVA Write a program that takes two command line arguments: an input file and an output file. The program should read the input file and replace the last letter of each word with a * character and write the result to the output file. The program should maintain the input file's line separators. The program should catch all possible checked exceptions and display an informative message. Notes: This program can be written in a single main method Remember that...

  • Write a program for IJVM called scramble that takes lowercase text from input and prints the...

    Write a program for IJVM called scramble that takes lowercase text from input and prints the next character (i.e. ‘b’ is printed as ‘c’) and uppercase text and prints the character before (‘B’ is printed as ‘A’). Print all other characters as is.

  • Using Java how would I write a program that reads and writes from binary or text...

    Using Java how would I write a program that reads and writes from binary or text files and gives me an output similar to this? Example Output: --------------------Configuration: <Default>-------------------- Enter the file name: kenb Choose binary or text file(b/t): b Choose read or write(r/w): w Enter a line of information to write to the file: lasdklj Would you like to enter another line? Y/N only n Continue? (y/n)y Enter the file name: kenb Choose binary or text file(b/t): b Choose...

  • C++ ONLY Write a program that reads a file, removes any blank lines at the beginning...

    C++ ONLY Write a program that reads a file, removes any blank lines at the beginning or end of the file, and writes the remaining lines back to the same file. C++ ONLY

  • After reading pages 330 - 336, write a program that takes two command line arguments which...

    After reading pages 330 - 336, write a program that takes two command line arguments which are file names. The program should read the first file line by line and write each line, in reverse order, into the second file. The program should include a "usage" method that displays the correct command line syntax if two file names are not provided. Example: if my input file says Hello, World! then my output file will contain !dlroW ,olleH Hints: Use CaesarCipher...

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