Create a program that takes 2 arguments from the terminal. The first argument is
ID: 3832750 • Letter: C
Question
Create a program that takes 2 arguments from the terminal. The first argument is an infile (which will be a .txt wordlist) and the second argument is an outfile. Prompt the user with 4 options on how to manipulate the wordlist. After the program completes the outfile should contain the modified wordlist. //sample output ./wlmanipulation infile.txt outfile.txt Choose an option below to modify your wordlist 1. Change the first letter to a capital letter. 2. Make each word lowercase 3. Make each word uppercase 4. Duplicate each word 10 times and display the word with it's duplicate # after it. Wordlist complete. Check "outfile.txt" for results.Explanation / Answer
Code:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
/*
Program name: word_manipulator.c
Program to manipulate the words in a file
*/
int main(int argc, char *argv[])
{
FILE *fin, *fout;
int option;
char word[1000];
int c, flag;
int j;
/* Ensuring atleast two arguments passed with first argument as input file and second output file */
if(argc!=3){
printf(" Two arguments must be passed");
printf(" Usage: %s <infile> <outfile>", argv[0]);
exit(1);
}
/* Proving set of options on how to manipulate the word */
printf(" 1.Change the first letter to a capital letter");
printf(" 2.Make each word lowercase");
printf(" 3.Make each word uppercase");
printf(" 4.Duplicate each word 10 times and display the word with its duplicate # after it");
printf(" Please select any of the above number option(1/2/3/4) ?");
scanf("%d",&option);
fin=fopen(argv[1],"r");
fout=fopen(argv[2],"w");
/* Translating first character of each word to uppercase */
if(option==1){
flag=1;
while((c=getc(fin))!=EOF){
if(flag){
putc(toupper(c),fout);
flag=0;
}
else
putc(c,fout);
if(c==' ' || c==' ' || c==' ')
flag=1;
}
}
/* Translating all the words to lowercase */
else if(option==2){
while((c=getc(fin))!=EOF)
putc(tolower(c),fout);
}
/* Translating all the words to uppercase */
else if(option==3){
while((c=getc(fin))!=EOF)
putc(toupper(c),fout);
}
/* Duplicating each word 10 times and showing the duplicate number for each word */
else if(option==4){
int i=0;
while((c=getc(fin))!=EOF){
word[i++]=c;
if (c==' ' || c==' ' || c==' '){
word[i]='';
for(j=0;j<10;j++)
fprintf(fout,"%s%d ",word, j);
i=0;
}
}
}
fclose(fin);
fclose(fout);
return 0;
}
186590cb0725:Chegg bonkv$
Input file:
186590cb0725:Chegg bonkv$ cat infile.txt
This is a first course in application development. Applications are computer programs developed to support human activity in enterprise and other social context Example or application might include programs to help run a business manage personal information or provide entertainment The emphasis of this course is on learning to translate practical problems through domain analysis into software applications usable in a human or organizational context It will focus on the knowledge needed to create applications that use high level programming languages
186590cb0725:Chegg bonkv$ gcc word_manipulator.c
Executing script and output:
186590cb0725:Chegg bonkv$ ./a.out infile.txt outfile.txt
1.Change the first letter to a capital letter
2.Make each word lowercase
3.Make each word uppercase
4.Duplicate each word 10 times and display the word with its duplicate # after it
Please select any of the above number option(1/2/3/4) ?1
Output file after change:
186590cb0725:Chegg bonkv$ cat outfile.txt
This Is A First Course In Application Development. Applications Are Computer Programs Developed To Support Human Activity In Enterprise And Other Social Context Example Or Application Might Include Programs To Help Run A Business Manage Personal Information Or Provide Entertainment The Emphasis Of This Course Is On Learning To Translate Practical Problems Through Domain Analysis Into Software Applications Usable In A Human Or Organizational Context It Will Focus On The Knowledge Needed To Create Applications That Use High Level Programming Languages
Executing script and output:
186590cb0725:Chegg bonkv$ ./a.out infile.txt outfile.txt
1.Change the first letter to a capital letter
2.Make each word lowercase
3.Make each word uppercase
4.Duplicate each word 10 times and display the word with its duplicate # after it
Please select any of the above number option(1/2/3/4) ?2
Output file after change:
186590cb0725:Chegg bonkv$ cat outfile.txt
this is a first course in application development. applications are computer programs developed to support human activity in enterprise and other social context example or application might include programs to help run a business manage personal information or provide entertainment the emphasis of this course is on learning to translate practical problems through domain analysis into software applications usable in a human or organizational context it will focus on the knowledge needed to create applications that use high level programming languages
Executing script and output:
186590cb0725:Chegg bonkv$ ./a.out infile.txt outfile.txt
1.Change the first letter to a capital letter
2.Make each word lowercase
3.Make each word uppercase
4.Duplicate each word 10 times and display the word with its duplicate # after it
Please select any of the above number option(1/2/3/4) ?3
Output file after change:
186590cb0725:Chegg bonkv$ cat outfile.txt
THIS IS A FIRST COURSE IN APPLICATION DEVELOPMENT. APPLICATIONS ARE COMPUTER PROGRAMS DEVELOPED TO SUPPORT HUMAN ACTIVITY IN ENTERPRISE AND OTHER SOCIAL CONTEXT EXAMPLE OR APPLICATION MIGHT INCLUDE PROGRAMS TO HELP RUN A BUSINESS MANAGE PERSONAL INFORMATION OR PROVIDE ENTERTAINMENT THE EMPHASIS OF THIS COURSE IS ON LEARNING TO TRANSLATE PRACTICAL PROBLEMS THROUGH DOMAIN ANALYSIS INTO SOFTWARE APPLICATIONS USABLE IN A HUMAN OR ORGANIZATIONAL CONTEXT IT WILL FOCUS ON THE KNOWLEDGE NEEDED TO CREATE APPLICATIONS THAT USE HIGH LEVEL PROGRAMMING LANGUAGES
Executing script and output:
186590cb0725:Chegg bonkv$ ./a.out infile.txt outfile.txt
1.Change the first letter to a capital letter
2.Make each word lowercase
3.Make each word uppercase
4.Duplicate each word 10 times and display the word with its duplicate # after it
Please select any of the above number option(1/2/3/4) ?4
Output file after change:
186590cb0725:Chegg bonkv$ cat outfile.txt
This 0 This 1 This 2 This 3 This 4 This 5 This 6 This 7 This 8 This 9 is 0 is 1 is 2 is 3 is 4 is 5 is 6 is 7 is 8 is 9 a 0 a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 first 0 first 1 first 2 first 3 first 4 first 5 first 6 first 7 first 8 first 9 course 0 course 1 course 2 course 3 course 4 course 5 course 6 course 7 course 8 course 9 in 0 in 1 in 2 in 3 in 4 in 5 in 6 in 7 in 8 in 9 application 0 application 1 application 2 application 3 application 4 application 5 application 6 application 7 application 8 application 9 development. 0 development. 1 development. 2 development. 3 development. 4 development. 5 development. 6 development. 7 development. 8 development. 9 Applications 0 Applications 1 Applications 2 Applications 3 Applications 4 Applications 5 Applications 6 Applications 7 Applications 8 Applications 9 are 0 are 1 are 2 are 3 are 4 are 5 are 6 are 7 are 8 are 9 computer 0 computer 1 computer 2 computer 3 computer 4 computer 5 computer 6 computer 7 computer 8 computer 9 programs 0 programs 1 programs 2 programs 3 programs 4 programs 5 programs 6 programs 7 programs 8 programs 9 developed 0 developed 1 developed 2 developed 3 developed 4 developed 5 developed 6 developed 7 developed 8 developed 9 to 0 to 1 to 2 to 3 to 4 to 5 to 6 to 7 to 8 to 9 support 0 support 1 support 2 support 3 support 4 support 5 support 6 support 7 support 8 support 9 human 0 human 1 human 2 human 3 human 4 human 5 human 6 human 7 human 8 human 9 activity 0 activity 1 activity 2 activity 3 activity 4 activity 5 activity 6 activity 7 activity 8 activity 9 in 0 in 1 in 2 in 3 in 4 in 5 in 6 in 7 in 8 in 9 enterprise 0 enterprise 1 enterprise 2 enterprise 3 enterprise 4 enterprise 5 enterprise 6 enterprise 7 enterprise 8 enterprise 9 and 0 and 1 and 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9 other 0 other 1 other 2 other 3 other 4 other 5 other 6 other 7 other 8 other 9 social 0 social 1 social 2 social 3 social 4 social 5 social 6 social 7 social 8 social 9 context 0 context 1 context 2 context 3 context 4 context 5 context 6 context 7 context 8 context 9 Example 0 Example 1 Example 2 Example 3 Example 4 Example 5 Example 6 Example 7 Example 8 Example 9 or 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 application 0 application 1 application 2 application 3 application 4 application 5 application 6 application 7 application 8 application 9 might 0 might 1 might 2 might 3 might 4 might 5 might 6 might 7 might 8 might 9 include 0 include 1 include 2 include 3 include 4 include 5 include 6 include 7 include 8 include 9 programs 0 programs 1 programs 2 programs 3 programs 4 programs 5 programs 6 programs 7 programs 8 programs 9 to 0 to 1 to 2 to 3 to 4 to 5 to 6 to 7 to 8 to 9 help 0 help 1 help 2 help 3 help 4 help 5 help 6 help 7 help 8 help 9 run 0 run 1 run 2 run 3 run 4 run 5 run 6 run 7 run 8 run 9 a 0 a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 business 0 business 1 business 2 business 3 business 4 business 5 business 6 business 7 business 8 business 9 manage 0 manage 1 manage 2 manage 3 manage 4 manage 5 manage 6 manage 7 manage 8 manage 9 personal 0 personal 1 personal 2 personal 3 personal 4 personal 5 personal 6 personal 7 personal 8 personal 9 information 0 information 1 information 2 information 3 information 4 information 5 information 6 information 7 information 8 information 9 or 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 provide 0 provide 1 provide 2 provide 3 provide 4 provide 5 provide 6 provide 7 provide 8 provide 9 entertainment 0 entertainment 1 entertainment 2 entertainment 3 entertainment 4 entertainment 5 entertainment 6 entertainment 7 entertainment 8 entertainment 9 The 0 The 1 The 2 The 3 The 4 The 5 The 6 The 7 The 8 The 9 emphasis 0 emphasis 1 emphasis 2 emphasis 3 emphasis 4 emphasis 5 emphasis 6 emphasis 7 emphasis 8 emphasis 9 of 0 of 1 of 2 of 3 of 4 of 5 of 6 of 7 of 8 of 9 this 0 this 1 this 2 this 3 this 4 this 5 this 6 this 7 this 8 this 9 course 0 course 1 course 2 course 3 course 4 course 5 course 6 course 7 course 8 course 9 is 0 is 1 is 2 is 3 is 4 is 5 is 6 is 7 is 8 is 9 on 0 on 1 on 2 on 3 on 4 on 5 on 6 on 7 on 8 on 9 learning 0 learning 1 learning 2 learning 3 learning 4 learning 5 learning 6 learning 7 learning 8 learning 9 to 0 to 1 to 2 to 3 to 4 to 5 to 6 to 7 to 8 to 9 translate 0 translate 1 translate 2 translate 3 translate 4 translate 5 translate 6 translate 7 translate 8 translate 9 practical 0 practical 1 practical 2 practical 3 practical 4 practical 5 practical 6 practical 7 practical 8 practical 9 problems 0 problems 1 problems 2 problems 3 problems 4 problems 5 problems 6 problems 7 problems 8 problems 9 through 0 through 1 through 2 through 3 through 4 through 5 through 6 through 7 through 8 through 9 domain 0 domain 1 domain 2 domain 3 domain 4 domain 5 domain 6 domain 7 domain 8 domain 9 analysis 0 analysis 1 analysis 2 analysis 3 analysis 4 analysis 5 analysis 6 analysis 7 analysis 8 analysis 9 into 0 into 1 into 2 into 3 into 4 into 5 into 6 into 7 into 8 into 9 software 0 software 1 software 2 software 3 software 4 software 5 software 6 software 7 software 8 software 9 applications 0 applications 1 applications 2 applications 3 applications 4 applications 5 applications 6 applications 7 applications 8 applications 9 usable 0 usable 1 usable 2 usable 3 usable 4 usable 5 usable 6 usable 7 usable 8 usable 9 in 0 in 1 in 2 in 3 in 4 in 5 in 6 in 7 in 8 in 9 a 0 a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 human 0 human 1 human 2 human 3 human 4 human 5 human 6 human 7 human 8 human 9 or 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 organizational 0 organizational 1 organizational 2 organizational 3 organizational 4 organizational 5 organizational 6 organizational 7 organizational 8 organizational 9 context 0 context 1 context 2 context 3 context 4 context 5 context 6 context 7 context 8 context 9 It 0 It 1 It 2 It 3 It 4 It 5 It 6 It 7 It 8 It 9 will 0 will 1 will 2 will 3 will 4 will 5 will 6 will 7 will 8 will 9 focus 0 focus 1 focus 2 focus 3 focus 4 focus 5 focus 6 focus 7 focus 8 focus 9 on 0 on 1 on 2 on 3 on 4 on 5 on 6 on 7 on 8 on 9 the 0 the 1 the 2 the 3 the 4 the 5 the 6 the 7 the 8 the 9 knowledge 0 knowledge 1 knowledge 2 knowledge 3 knowledge 4 knowledge 5 knowledge 6 knowledge 7 knowledge 8 knowledge 9 needed 0 needed 1 needed 2 needed 3 needed 4 needed 5 needed 6 needed 7 needed 8 needed 9 to 0 to 1 to 2 to 3 to 4 to 5 to 6 to 7 to 8 to 9 create 0 create 1 create 2 create 3 create 4 create 5 create 6 create 7 create 8 create 9 applications 0 applications 1 applications 2 applications 3 applications 4 applications 5 applications 6 applications 7 applications 8 applications 9 that 0 that 1 that 2 that 3 that 4 that 5 that 6 that 7 that 8 that 9 use 0 use 1 use 2 use 3 use 4 use 5 use 6 use 7 use 8 use 9 high 0 high 1 high 2 high 3 high 4 high 5 high 6 high 7 high 8 high 9 level 0 level 1 level 2 level 3 level 4 level 5 level 6 level 7 level 8 level 9 programming 0 programming 1 programming 2 programming 3 programming 4 programming 5 programming 6 programming 7 programming 8 programming 9 languages
0 languages
1 languages
2 languages
3 languages
4 languages
5 languages
6 languages
7 languages
8 languages
9 186590cb0725:Chegg bonkv$
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.