Programming in C.
Name this program schwifty.c - This program reads a text file and makes it schwifty, but the user determines the schwiftiness. The user supplies the filename to schwift and a string containing a sequence of the following characters to determine the schwiftiness via command line arguments:
Example execution
ex.txt | ./a.out ex.txt R | ./a.out ex.txt D | ./a.out ex.txt RD | ./a.out ex.txt RDIL |
---|---|---|---|---|
Oh, yeah! You gotta get schwifty. empty line |
,Oh !yeah uYo agott tge .schwifty empty line |
Ng, xdzg! Xnt fnssz fds rbgvhesx. empty line |
,Ng !xdzg tXn zfnss sfd .rbgvhesx empty line |
Oh, yeah! You gotta get schwifty. empty line |
Notes
I have included my code and screenshots in this answer. In case, there is any indentation issue due to editor, then please refer to code screenshots to avoid confusion.
-------------------schwifty.c-------------------
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void left(char word[]); //declarations
void right(char word[]);
void inc(char word[]);
void dec(char word[]);
int main(int argc, char** argv)
{
if (argc !=3){
printf("Invalid number of
arguments\n"); //check for number of arguments
return 0;
}
FILE *fin ;
fin = fopen(argv[1], "r") ; //file opening
failed
if(fin == NULL){
printf("Could not open file
'%s'\n", argv[1]);
return 0;
}
int i = 0;
for(i = 0; i< strlen(argv[2]); i++){
if(argv[2][i]!='L' &&
argv[2][i]!='R' && argv[2][i]!='I' &&
argv[2][i]!='D') { //if wrong char in input
printf("You
threw off my schwiftiness with schwifty %c!\n", argv[2][i]);
return 0;
}
}
char text[1001];
while(fgets(text, 1000, fin)) //read line by
line
{
char* word = strtok(text, " \n");
//split each word from the line sparated by newline or space
while(word!=NULL) //if word is
not empty
{
//printf("%s\n",
word);
for(i = 0; i<
strlen(argv[2]); i++) //perform operations
{
if(argv[2][i]=='L')
{
left(word);
}
if(argv[2][i]=='R')
{
right(word);
}
if(argv[2][i]=='I')
{
inc(word);
}
if(argv[2][i]=='D')
{
dec(word);
}
}
printf("%s\n",
word); //print output for that word after all operations are
completed
word =
strtok(NULL, " \n"); //find next word from the line
}
}
return 0;
}
void left(char word[]) //shifts left
{
int i;
char output[100]; //create output array
int out_i = 0;
for(i = 1; i < strlen(word); i++){ //second char to
last
output[out_i++] = word[i];
}
output[out_i++] = word[0]; //first char
output[out_i] = '\0'; //place null char at the
end
strcpy(word, output); //update word with output array
value
}
void right(char word[])
{
char output[100];
int out_i = 0;
output[out_i++] = word[strlen(word)-1]; //last
char
int i;
for(i = 0; i < strlen(word)-1; i++){
output[out_i++] = word[i]; //1st
chat to last but one char
}
output[out_i] = '\0';
strcpy(word, output);
}
void inc(char word[])
{
char output[100];
int out_i = 0;
int i;
for(i =0; i < strlen(word); i++){
if(word[i] == 'Z') //special
cases
output[out_i++]
= 'A';
else if(word[i] == 'z')
output[out_i++]
= 'a';
else if(word[i] == '9')
output[out_i++]
= '0';
else if(word[i] >= 'A'
&& word[i] <= 'Y') //A-Y char
output[out_i++]
= word[i]+1;
else if(word[i] >= 'a'
&& word[i] <= 'y') //a-y char
output[out_i++]
= word[i]+1;
else if(word[i] >= '0'
&& word[i] <= '8') //0-8 char
output[out_i++]
= word[i]+1;
else
output[out_i++]
= word[i]; //remaining chars are not altered
}
output[out_i] = '\0';
strcpy(word, output);
}
void dec(char word[])
{
char output[100];
int out_i = 0;
int i;
for(i =0; i < strlen(word); i++){
if(word[i] == 'A') //special
cases
output[out_i++]
= 'Z';
else if(word[i] == 'a')
output[out_i++]
= 'z';
else if(word[i] == '0')
output[out_i++]
= '9';
else if(word[i] >= 'B'
&& word[i] <= 'Z') //B-Y
output[out_i++]
= word[i]-1;
else if(word[i] >= 'b'
&& word[i] <= 'z') //b-y
output[out_i++]
= word[i]-1;
else if(word[i] >= '1'
&& word[i] <= '9') //1-9
output[out_i++]
= word[i]-1;
else
output[out_i++]
= word[i]; //remaining chars are not altered
}
output[out_i] = '\0';
strcpy(word, output);
}
-------------------Screenshot schwifty.c-------------------
-------------------Output-------------------
----------------------------------------------------
I hope this helps you,
Please rate this answer if it helped you,
Thanks for the opportunity
Programming in C. Name this program schwifty.c - This program reads a text file and makes...
USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...
C Language program. Please follow the instructions given. Must use functions, pointers, and File I/O. Thank you. Use the given function to create the program shown in the sample run. Your program should find the name of the file that is always given after the word filename (see the command line in the sample run), open the file and print to screen the contents. The type of info held in the file is noted by the word after the filename:...
I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...
Write a program that takes a file as input and checks whether or not the content of the file is balanced. In the context of this assignment “balanced” means that your program will check to make sure that for each left bracket there is a closing right bracket. Examples: [ ( ) ] { } à balanced. [ ( ] ) { } à unbalanced. Here is the list of brackets/braces that program must support: (: left parentheses...
In python Count the frequency of each word in a text file. Let the user choose a filename to read. 1. The program will count the frequency with which each word appears in the text. 2. Words which are the spelled the same but differ by case will be combined. 3. Punctuation should be removed 4. If the file does not exist, use a ‘try-execption’ block to handle the error 5. Output will list the words alphabetically, with the word...
need this in c programming and you can edit the code below. also give me screenshot of the output #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define LINE_SIZE 1024 void my_error(char *s) { fprintf(stderr, "Error: %s\n", s); perror("errno"); exit(-1); } // This funciton prints lines (in a file) that contain string s. // assume all lines has at most (LINE_SIZE - 2) ASCII characters. // // Functions that may be called in this function: // fopen(), fclose(), fgets(), fputs(),...
QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...
Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...
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.
In c programming . Part A: Writing into a Sequential File Write a C program called "Lab5A.c" to prompt the user and store 5 student records into a file called "stdInfo.txt". This "stdInfo.txt" file will also be used in the second part of this laboratory exercise The format of the file would look like this sample (excluding the first line) ID FIRSTNAME LASTNAME GPA YEAR 10 jack drell 64.5 2018 20 mina alam 92.3 2016 40 abed alie 54.0 2017...