-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_filecontent_toanother_file.c
More file actions
75 lines (75 loc) · 1.28 KB
/
write_filecontent_toanother_file.c
File metadata and controls
75 lines (75 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void StartWriting(char *f)
{
FILE *fp;
fp = fopen(f,"w");
if(fp == NULL){
fprintf(stderr,"Error in Opening File.\n");
}
else{
char ch;
int i=1;
while(i<=100)
{
printf("Enter %d character:",i);
ch=fgetc(stdin);
if(ch=='\n')
{
printf("ENTER KEY is pressed.\n");
break;
}
else
{
fputc(ch,fp);i++;
}
ch=getchar();
}
fclose(fp);
}
}
void main(int argc, char** argv)
{
char* f;
int flag=0;
char f2[30];
if(argc == 1)
{
printf("Enter the file path:\n");
gets(f2);
if(fopen(f2, "r"))
{printf("Cannot open the file because %s already exist.\n",f2);flag++;}
else
StartWriting(f2);
if(flag>0)
{
printf("Enter the file path:\n");
gets(f2);
if(fopen(f2, "r"))
printf("Cannot open the file because %s already exist.\n",f2);
else
StartWriting(f2);
}
}
else
{
int flag=0;
f = argv[1];
if(fopen(f, "r"))
{
printf("Cannot open the file because %s already exist.\n",f);flag++;
}
else
StartWriting(f);
if(flag>0)
{
printf("Enter the file path:\n");
gets(f2);
if(fopen(f2, "r"))
printf("Cannot open the file because %s already exist.\n",f2);
else
StartWriting(f2);
}
}
}