// Program by Akash Tripathi (@proakash256)
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("Enter the content that you want to copy
to other file :\n\n");
FILE *filepointer;
char *s;
s = malloc(1024 * sizeof(char));
gets(s);
s = realloc(s, strlen(s) + 1);
filepointer = fopen("input.txt", "w");
if (filepointer == NULL)
{
printf("Sorry! Couldn't find the file.");
}
else
{
for(int i = 0; s[i] != '\0'; i = i + 1)
{
fputc(s[i] , filepointer);
}
fclose(filepointer);
}
printf("\ninput.txt file successfully created.\n\n");
char *s1;
s1 = malloc(1024 * sizeof(char));
int i = 0;
filepointer = fopen("input.txt", "r");
do
{
if (feof(filepointer) != 0)
break;
s1[i] = fgetc(filepointer);
i = i + 1;
} while(1);
s1 = realloc(s1, strlen(s1) + 1);
fclose(filepointer);
filepointer = fopen("output.txt", "w");
if (filepointer == NULL)
{
printf("Sorry! Couldn't find the file.");
}
else
{
for(int i = 0; s1[i] != '\0'; i = i + 1)
{
fputc(s1[i] , filepointer);
}
fclose(filepointer);
}
printf("\noutput.txt file successfully created.\n\n");
free(s);
free(s1);
return 0;
}
Comments
Post a Comment