#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define LOOPS 26
#define FILENAME "output"
#define RETRYTIME 3
int main(int argc , char **argv)
{
/*make file and fail check*/
FILE * fp = fopen(FILENAME , "w+");
if (NULL == fp) {
perror("Can't open file!\n");
exit(0);
}
/*make string pointer*/
int flag = RETRYTIME; //retry times!
MEM_J:
char * sp = (char *)malloc(sizeof(char) * LOOPS * 2);
/*location fail!*/
if (NULL == sp) {
free(sp);
perror("Memory location failured!\n");
--flag;
assert(flag != 0); //time over!
goto MEM_J;
}
/*make string*/
int loop = LOOPS;
int i = 0;
char ch = 'a';
while (loop) {
sp[i++] = ch;
sp[i++] = '\n';
++ch;
--loop;
}
/*write string to file*/
fwrite(sp , sizeof(char) , LOOPS * 2 , fp);
/*resource return*/
fclose(fp);
free(sp);
return EXIT_SUCCESS;
}