|
|
1.1 root 1:
2:
3: fputc() STDIO fputc()
4:
5:
6:
7:
8: Write character into file stream
9:
10: #include <stdio.h>
11: iinntt ffppuuttcc(_c, _f_p) cchhaarr _c; FFIILLEE *_f_p;
12:
13: fputc writes the character c into the file stream pointed to by
14: fp. It returns c if c was written successfully.
15:
16: ***** Example *****
17:
18: The following example uses ffppuuttcc to write the contents of one
19: file into another.
20:
21:
22: #include <stdio.h>
23:
24:
25:
26: void fatal(message)
27: char *message;
28: {
29: fprintf(stderr, "%s\n", message);
30: exit(1);
31: }
32:
33:
34:
35: main()
36: {
37: FILE *fp, *fout;
38: int ch;
39: int infile[20];
40: int outfile[20];
41:
42:
43:
44: printf("Enter name to copy: ");
45: gets(infile);
46: printf("Enter name of new file: ");
47: gets(outfile);
48:
49:
50:
51: if ((fp = fopen(infile, "r")) == NULL)
52: fatal("Cannot write input file");
53:
54:
55:
56: if ((fout = fopen(outfile, "w")) != NULL)
57: fatal("Cannot write output file");
58:
59:
60:
61:
62:
63:
64: COHERENT Lexicon Page 1
65:
66:
67:
68:
69: fputc() STDIO fputc()
70:
71:
72:
73: while ((ch = fgetc(fp)) != EOF)
74: fputc(ch, fout);
75: }
76:
77:
78: ***** See Also *****
79:
80: STDIO
81:
82: ***** Diagnostics *****
83:
84: fputc returns EOF when a write error occurs, e.g., when a disk
85: runs out of space.
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130: COHERENT Lexicon Page 2
131:
132:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.