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
#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;
}
Comments
Leave a comment