Hi everyone, I have a C programming problem, answers are better with explanations.
Background Materials:
The Task:
The Answer:
The completed C code.
Below is the file charIO4C.c:
#include <stdio.h> #include <ctype.h> #define QUIT_LETTER 'q' int main(void) { int c, line_length; // Each pass through the outer loop reads a line of input. while (1) { printf("\nEnter a line of text. (To quit, start the line with %c.)\n", QUIT_LETTER); c = fgetc(stdin); if (c == EOF || c == QUIT_LETTER) break; // Leave outer loop. line_length = 0; printf("Changing uppercase to lowercase ...\n"); // Inner loop reads chars until '\n' or EOF is found. while (c != '\n' && c != EOF) { line_length++; fputc(tolower(c), stdout); c = fgetc(stdin); } fputc('\n', stdout); printf("Length of line, not counting '\\n', was %d.\n", line_length); } printf("Bye!\n"); return 0; }
Thanks a lot!
//Modified program will print number of alphabets in addition to the number of characters read
#include <stdio.h>
#include <ctype.h>
#define QUIT_LETTER 'q'
int main(void)
{
int c, line_length, tot_alpha;
// Each pass through the outer loop reads a line of input.
while (1) {
printf("\nEnter a line of text. (To quit, start the line with %c.)\n",
QUIT_LETTER);
c = fgetc(stdin);
if (c == EOF || c == QUIT_LETTER)
break; // Leave outer loop.
line_length = 0;
tot_alpha = 0; //variables to hold number of alpabets
printf("Changing uppercase to lowercase ...\n");
// Inner loop reads chars until '\n' or EOF is found.
while (c != '\n' && c != EOF) {
line_length++;
if(isalpha(c)!=0) //Checking for alphabets
tot_alpha++;
fputc(tolower(c), stdout);
c = fgetc(stdin);
}
fputc('\n', stdout);
printf("Length of line, not counting '\\n', was %d.\n", line_length);
//Printing total alphabets
printf("%d of the characters in the line were letters\n", tot_alpha);
}
printf("Bye!\n");
return 0;
}
//Modified program will print number of digits in addition to the number of characters read
#include <stdio.h>
#include <ctype.h>
#define QUIT_LETTER 'q'
int main(void)
{
int c, line_length, tot_digits;
// Each pass through the outer loop reads a line of input.
while (1) {
printf("\nEnter a line of text. (To quit, start the line with %c.)\n",
QUIT_LETTER);
c = fgetc(stdin);
if (c == EOF || c == QUIT_LETTER)
break; // Leave outer loop.
line_length = 0;
tot_digits = 0; //variables to hold number of digits
printf("Changing uppercase to lowercase ...\n");
// Inner loop reads chars until '\n' or EOF is found.
while (c != '\n' && c != EOF) {
line_length++;
if(isdigit(c)!=0) //Checking for digit
tot_digits++;
fputc(tolower(c), stdout);
c = fgetc(stdin);
}
fputc('\n', stdout);
printf("Length of line, not counting '\\n', was %d.\n", line_length);
//Printing total digits
printf("%d of the characters in the line were digits\n", tot_digits);
}
printf("Bye!\n");
return 0;
}
Hi everyone, I have a C programming problem, answers are better with explanations. Background Materials: The...
My question is listed the below please any help this assignment ; There is a skeleton code: copy_file_01.c #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { char ch ; FILE *source , *target; if(argc != 3){ printf ("Usage: copy file1 file2"); exit(EXIT_FAILURE); } source = fopen(argv[1], "r"); if (source == NULL) { printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } target = fopen(argv[2], "w"); if (target == NULL) { fclose(source); printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } while ((ch...
Hi everyone, I have a problem about C programming. Background Material: The figure 6 is as below: The task: Download the file 55.c. Study the C code, then build an executable and run it to see what the output is. Modify the program so that the output is The string in buffer is "In C the value of 12 + 34 / 5 is 18." Do this by looking up decimal values for ASCII codes in Figure 6 and typing...
Write a C Program that uses file handling operations of C language to copy the contents of a file called “original.dat” to another file called “copy2.dat”. Here, you will read and write from/to the files line by line with the help of fgets() and fputs() functions. Sample file “original.dat” has been provided. Please note that the new file “copy2.dat” should have exactly same contents as in “original.dat”. #include <stdio.h> int main() { FILE *fptr1, *fptr2; if((fptr1=fopen("original.dat","r"))==NULL) printf("\n Error opening File");...
Convert C to C++ I need these 4 C file code convert to C++. Please Convert it to C++ //////first C file: Wunzip.c #include int main(int argc, char* argv[]) { if(argc ==1){ printf("wunzip: file1 [file2 ...]\n"); return 1; } else{ for(int i =1; i< argc;i++){ int num=-1; int numout=-1; int c; int c1; FILE* file = fopen(argv[i],"rb"); if(file == NULL){ printf("Cannot Open File\n"); return 1; } else{ while(numout != 0){ numout = fread(&num, sizeof(int), 1, file); c...
Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....
I did the assigment but inside mainWrite a C program (called counting.c) that counts the number of characters, words and lines readfrom standard input (stdin) until EOF is reached. This means counting.c must contain a mainfunction along with other function.- Assume the input is ASCII text of any length.-Every byte read from stdin counts as a character except EOF.- Words are defined as contiguous sequences of letters (a through z, A through Z) and the apostrophe ( ' which has...
A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...
The program is written in c. How to implement the following code without using printf basically without stdio library? You are NOT allowed to use any functions available in <stdio.h> . This means you cannot use printf() to produce output. (For example: to print output in the terminal, you will need to write to standard output directly, using appropriate file system calls.) 1. Opens a file named logfle.txt in the current working directory. 2. Outputs (to standard output usually the...
C Language Programming. Using the program below - When executing on the command line only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the...
Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...