Q:

Write a C Program to Replace First Letter with Capital Letter

0

Write a C Program to Replace First Letter with Capital Letter. Here’s simple Program to Replace First Letter with Capital Letter in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Below is the source code for C Program to Replace First Letter with Capital Letter which is successfully compiled and run on Windows System to produce desired output as shown below :

 
 


SOURCE CODE : :

/*  C Program to Replace First Letter with Capital Letter  */

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

int main()
{
    FILE *fp1;
    int return_val;
    char * arrr = "C:\\Users\\acer\\Documents\\file4.txt";

    if ((fp1 = fopen(arrr,"r")) == NULL)
    {
        printf("file cant be opened");
        exit(0);
    }
    return_val = init_cap_file(fp1);
    if (return_val == 1)
    {
        printf("\nsuccess");
    }
    else
    {
        printf("\n failure");
    }

    return 0;
}

int init_cap_file(FILE *fp1)
{
    char ch;

    ch = fgetc(fp1);
    if (ch >= 97 && ch <= 122)
    {
        fseek(fp1, -1L, 1);
        fputc(ch - 32, fp1);
    }
    while (ch != EOF)
    {
        if (ch == ' '|| ch == '\n')
        {
            ch = fgetc(fp1);
            if (ch >= 97 && ch <= 122)
            {
                fseek(fp1, -1L, 1);
                fputc(ch - 32, fp1);
            }
        }
        else
            ch = fgetc(fp1);
    }
    return 1;
}

OUTPUT : :


success

Above is the source code for C Program to Replace First Letter with Capital Letter which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C Program to Count Lines,Blank Lines,Comme... >>
<< C Program to Maintain Employee Records using File ...