- 论坛徽章:
- 2
|
回复 25# shihyu
比如:
- int copy(char const* dst, char const* src)
- {
- FILE *d, *s;
- if (s = fopen(src, "rb"), !s)
- return error; // 出口1
- if (d = fopen(dst, "wb"), !d) {
- fclose(s);
- return error; // 出口2
- }
- // copy s to d ...
- fclose(d);
- fclose(s);
- return ok; // 出口3
- }
复制代码
- int copy(char const* dst, char const* src)
- {
- FILE *d=0, *s=0;
- int result = error;
- do {
- if (s = fopen(src, "rb"), !s) break;
- if (d = fopen(dst, "wb"), !d) break;
- // copy s to d ...
- result = 0;
- } while (0)
- if (d) fclose(d);
- if (s) fclose(s);
- return result; // 唯一出口
- }
复制代码 |
|