Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- // We have name of the source file
- char *somename = "testfile";
- // Set file name as our name
- const int SIZE_filename = strlen(somename) + 10;
- char filename[SIZE_filename];
- strcpy(filename, somename);
- // Set output name as file name with "_out" appended
- const int SIZE_outfilename = strlen(filename) + 10;
- char outfilename[SIZE_outfilename];
- strcpy(outfilename, filename);
- strcat(outfilename, "_out");
- FILE *file;
- FILE *out;
- // Open files with their names
- file = fopen(filename, "r");
- out = fopen(outfilename, "w");
- // Read from source and write to the output file
- char c;
- while ((c = fgetc(file)) != EOF) {
- fputc(c, out);
- }
- fclose(file);
- fclose(out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement