Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program (stored in ~/One/p1.c) that will read data from standard input

ID: 3542206 • Letter: W

Question

Write a C program (stored in ~/One/p1.c) that will read data from standard

input one character at a time and output the results to standard output.

Roughly, your program should mostly copy the input stream to the output stream,

but it should delete all non-ASCII characters, 'make visible' the

'non-printing characters' from the input, and then truncate lines that would

extend past column 72 as it writes out the (new and improved) data.

Specifically, the changes that should be made to the incoming data are:


1) remove all non-printing ASCII characters (character codes 0 through 31,

   and 127) and replace them with the same sort of codes the vi

   editor uses.  For example, the bell character (character code 7)

   is replaced by the two printable characters "^" and "G" (G is the seventh

   letter of the alphabet).  Most of these are shown under the 'Ctrl char'

   column of http://www.physics.udel.edu/~watson/scen103/ascii.html

   If you have a copy of the Foster "C By Discovery" text (highly recommended,

   and dirt cheap if you buy an older edition), Appendix-I also lists the ASCII

   character set, and it shows all the proper two-character sequences that

   should be used for the non-printing characters. There are two special cases:

   Newlines should be replaced by a dollar sign ("$") and then an actual

   newline.  Replace the delete character by "^?" (Actually, if you use modular

   arithmetic, the delete character does not have to be a special case.)


2) delete all non-ASCII characters (those with character codes 128 through 255).


3) truncate all output lines that would otherwise extend past column 72.

   That is:  If, after the expansions and contractions suggested above, you

   have output 72 characters since the last newline, immediately output an

   additional newline (with no '$' in front of it, in this case).  Ignore the

   rest of the characters on that input line [that is, do NOT print them!],

   and then resume sending characters to stdout when you find the beginning

   of the 'next' input line.


Note that in the ASCII sequence, 'Z' (character code 90) is followed by '['

(character code 91), and, quite conveniently, the non-printing character

after "^Z" (character code 26) is designated "^[" (character code 27).

Similarly, the character just before 'A' happens to be '@', which

will also be very convenient.  DO NOT write a bazillion 'if' statements

to handle the character translations; a SINGLE arithmetic formula should

suffice to cover all the characters in (1) above (except one or two 'special

cases' noted above, e.g., delete and newline).


Here is what I have so far(No need for scanf): It doesn't input the right char and repeats.


#include <stdio.h>


int main( void )

{

    int iochar, curr = 0, coloumn = 72;

    char ch;

    while ( ( iochar = getchar() ) != EOF ) {

            a:

        putchar( iochar );

        if (curr>72)

            printf(" ");

        if (iochar > 127)

            goto a;

        else if (iochar < 32) {

            iochar += 64;

            ch = iochar;

            printf("^%c", ch);

            curr+=2;

        }

        else if (iochar == 127) {

            printf("^?");

            curr+=2;

        }

        else {

                ch = iochar;

            printf("%c", ch);

            curr++;

        }

    }

}


Explanation / Answer

plz post the sample input & ouput .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote