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

Write a C program to capitalize the first character in each sentence from a give

ID: 3810419 • Letter: W

Question

Write a C program to capitalize the first character in each sentence from a given file. Assume a sentence ends with a period '.' To get the result, the execution of this program must be cooperated with the redirection feature in shell. For the program in (a), how to run it and count the most frequent digit in file test2.txt? Please write down the command you may need to use in terminal of Unix. Assume the program in (a) has a file name count.c. Write another C program to count the most frequent digit in a file. To get the result, the execution of this program must be cooperated with the redirection feature in shell.

Explanation / Answer

[a]

#include <stdio.h>
#include <stdlib.h>

int First_Upper(FILE *);

void main(int argc, char * argv[])

{
    char fp[10];
    FILE *fp1;
    int p;
    fp1 = fopen(argv[1], "r+");

    if (fp1 == NULL)

    {
        printf("cannot open the file ");
        exit(0);

    }

    p = First_Upper(fp1);

    if (p == 1)   

    {   
        printf("success");
    }

    else

    {

        printf("failure");

    }

    fclose(fp1);

}


int First_Upper(FILE *fp)

{
    char c;
    c = fgetc(fp);

    if (c >= 'a' && c <= 'z')

    {

        fseek(fp, -1L, 1);

        fputc(c - 32, fp);

    }

    while(c != EOF)   

    {

        if (c == ' ' || c == ' ')

        {

            c = fgetc(fp);

            if (c >= 'a' && c <= 'z')

            {

                fseek(fp, -1L, 1);

                fputc(c - 32, fp);

            }

        }

        else

        {

            c = fgetc(fp);

        }

    }

    return 1;

}

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