Question

In: Computer Science

Create a C Program that reads a file and replaces every other letter with an asterisk....

Create a C Program that reads a file and replaces every other letter with an asterisk. The first integer 'num' is the number of lines.

Include an "Error" Message and exit the program if:
   The wrong name for the input/output file is given
   The input/output file can not be opened

input.txt
7
Never
Have
We
Ever
Played
A
Game

output.txt
7
N*v*r
*a*e
W*
*v*r
*l*y*d
*
G*m*


Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<stdio.h>

int main(){

char in_fname[50], out_fname[50], line[100];

int num;

printf("Enter input filename: ");

scanf("%s", in_fname);

FILE *fin = fopen(in_fname, "r");

if(fin==NULL){

printf("Error: Unable to open input file!\n");

return -1;

}

printf("Enter output filename: ");

scanf("%s", out_fname);

FILE *fout = fopen(out_fname, "w");

if(fout==NULL){

printf("Error: Unable to open output file!\n");

return -1;

}

fscanf(fin, "%d", &num);

int j = 0, k;

for(int i=0; i<num; i++){

fscanf(fin, "\n%[^\n]s", line);

k = 0;

while(line[k]!='\0'){

if(j%2!=0)

line[k] = '*';

k++;

j++;

}

fprintf(fout, "%s\n", line);

}

fclose(fout);

fclose(fin);

return 0;

}


Related Solutions

This is C++ Create a program that reads an HTML file and converts it to plain...
This is C++ Create a program that reads an HTML file and converts it to plain text. Console: HTML Converter Grocery List * Eggs * Milk * Butter Specifications: The HTML file named groceries.html contains these HTML tags: <h1>Grocery List</h1> <ul> <li>Eggs</li> <li>Milk</li> <li>Butter</li> </ul> When the program starts, it should read the contents of the file, remove the HTML tags, remove any spaces to the left of the tags, add asterisks (*) before the list items, and display the...
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching...
Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching pairs of vehicle models and their respective makes Separate out the individual make and model on each line of the file Add the vehicle make to one list, and the vehicle model to another list; such that they are in the same relative position in each list Prompt the user to enter a vehicle model Search the list containing the vehicle models for a...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
C Programming Write a program in C that reads in a file, stores its contents as...
C Programming Write a program in C that reads in a file, stores its contents as a character array/pointer (char*) into an unsigned character array/pointer (unsigned char* message). Note: the input file can have one line or multiple lines and vary in length
Modify the program so that after it reads the line typed on the keyboard, it replaces...
Modify the program so that after it reads the line typed on the keyboard, it replaces the ‘\n’ character with a NUL character. Now you have stored the input as a C-style string, and you can echo it with: Explain what you did. #include <unistd.h> #include <string.h> int main(void) { char aString[200]; char *stringPtr = aString; write(STDOUT_FILENO, "Enter a text string: ", strlen("Enter a text string: ")); // prompt user read(STDIN_FILENO, stringPtr, 1); // get first character while (*stringPtr !=...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT