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

Make sure it reads from stdin and prints to stdout. it should be comprised of st

ID: 3702497 • Letter: M

Question

Make sure it reads from stdin and prints to stdout. it should be comprised of standard UNIX utilities (that is, it should not invoke any specialized C programs that you might have considered writing). You must make use of pipes rather than using files to store intermediate result.

Specifically, for each character you read, do one of the following 4 things: 1) delete all digits (the characters 0, 1, 2, ..., 9) that is, read it in, but then don't print it if was a digit. 2) Interchange the case of the alphabetic letters; that is, if you encounter an 'A', print out an 'a' instead, 'B' becomes 'b', etc. and likewise, 'a becomes 'A', 'z' becomes 2' 3) Every time a space character is encountered (ASCII code 32), print two spaces instead of just the one. 4) When you find consecutive empty lines, print just one empty line. For simplicity, we will distinguish between 'blank' and 'empty' empty' means "no characters except for a newline" - a line consisting of three tabs looks* blank, but it contains 3 characters, so it will not be considered empty. Essentially, this rule simply means "if you see a bunch of CONSECUTIVE newlines, print just one newline. 5) All other characters not mentioned above (such as tabs, "+, control characters, or whatever) are simply printed verbatim. Your main program should return a value when it finishes. Return one (1) if the output was unchanged from the input that was read in, and return zero (0) if you made at least one change (either by removing digits, deleting empty lines, doubling spaces, or changing case).

Explanation / Answer

Done part 2

#include <stdio.h>
#define MAX_SIZE 100 // Maximum string size

/* Toggle case function declaration */

void toggleCase(char * str);

int main()

{

    char str[MAX_SIZE];

    /* Input string from user */

    printf("Enter any string: ");
    gets(str);

    printf("String before toggling case: %s", str);

    toggleCase(str);

    printf("String after toggling case: %s", str);

    return 0;

}

/**

* Toggle case of each character in given string

*/

void toggleCase(char * str)

{

    int i = 0;

    while(str[i] != '')

    {

        if(str[i]>='a' && str[i]<='z')

        {

            str[i] = str[i] - 32;

        }

        else if(str[i]>='A' && str[i]<='Z')

        {

            str[i] = str[i] + 32;

        }

        i++;

    }

}


or in the place of togglecase function , we can make use of pointers as well.
void toggleCase(char * str)

{

    while(*str)

    {

        if(*str >= 'a' && *str <= 'z')

            *str = *str - 32;

        else if(*str >= 'A' && *str <= 'Z')

            *str = *str + 32;

str++;

    }

}

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