a) Write a program to prompt a user for a filename. Count: -the number of charac
ID: 3626740 • Letter: A
Question
a) Write a program to prompt a user for a filename. Count:-the number of characters in the file (letters or numbers)
-the number of words in the file
-the number of lines in the file
b) Create a setlist of enumerated constants called week that contains the days of the week. Have a variable today that is of type week. Assign a value to today. If the day is Monday through Friday, print " Go to work!" If the day is Saturday or Sunday, print " You can rest today!"
Explanation / Answer
PLEASE RATE #include #include #include #include read_file(char*); void main() { char ch,*filename="file.txt"; FILE *fpt; int space,digit,vow,conso; clrscr(); fpt=fopen(filename,"a+"); if(!fpt) { printf(" "%s" Not Found . terminating......",filename); exit(0); } space=digit=conso=vow=0; while((ch=fgetc(fpt))!=EOF) { if(isspace(ch)) space++; if(isdigit(ch)) digit++; if(isalpha(ch)) { switch(tolower(ch)) { case 'a' : vow++; break; case 'e' : vow++; break; case 'i' : vow++; break; case 'o' : vow++; break; case 'u' : vow++; break; default : conso++; break; } } } fflush(fpt); fprintf(fpt," No of vowels : %d",vow); fprintf(fpt," No of consonants : %d",conso); fprintf (fpt," No of digits : %d",digit); fprintf(fpt," no of white spaces : %d",space); fclose(fpt); printf(" FILENAME : "%s"",filename); read_file(filename); getch(); } read_file(char *filename) { char ch; FILE *read=fopen(filename,"r"); if(!read) { printf(" "%s" file could not be read!!--- ",filename); getch(); exit(0); } printf(" CONTENTS OF "%s" ",filename); while(1) { ch=fgetc(read); if(ch!=EOF) printf("%c",ch); else break; } fclose(read); //getch(); } ----------- (2) #include enum week{Saturday , Sunday , Monday , Tuesday, Wednesday , Thursday , Friday}; int main() { week today; today = Saturday; if(today >=2) printf("%s","go to work"); else printf("%s","take a rest"); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.