Answer to Question #258823 in C for Jainam

Question #258823

Write a file copy program that prompts the user to enter the name of a text file to act as the source file and the name of an output file. The program should use the toupper() function from ctype.h to convert all text to uppercase as it’s written to the output file. Use standard I/O and the text mode


1
Expert's answer
2021-10-30T00:39:02-0400
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
    FILE *fp, *neu;
    int zeichen;

    fp = fopen("test.txt", "r");
    neu = fopen("new.txt", "w");

    if(fp == NULL) {
        printf("Die Datei konnte nicht geoeffnet werden.\n");
        exit(EXIT_FAILURE);
    }

    while((zeichen = fgetc(fp)) != EOF) {
        if(zeichen == ' ') {
            fputc(zeichen, neu);
            zeichen = fgetc(fp);
            zeichen = toupper(zeichen);
            fputc(zeichen, neu);
        }
        else{
            fputc(zeichen, neu);
        }
    }
    fclose(fp);
    fclose(neu);
    remove("test.txt");
    rename("new.txt", "test.txt");
    printf("File has been changed.\n");
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS