Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int incr = STRLEN;
- exp = fopen(MY_FILE, "a");
- if(file == NULL){
- printf(ERROR);
- }
- else{
- char end[] = "STOP";
- int type = 1;
- do{
- char *str = (char *)malloc(STRLEN * sizeof(char));
- printf("Enter string: ");
- fgets(str, incr, stdin);
- if(strncmp(str, end, 4) == 0){
- break;
- }
- while(str[strlen(str)-1] != '\n'){
- incr = incr + STRLEN;
- char *newline = (char *)realloc(str, incr * sizeof(char));
- str = newline;
- fgets(str+strlen(str), STRLEN, stdin);
- }
- str[strlen(str)- 2] = '\0';
- fprintf(exp,"%d;%s\n",type, str);
- free(str);
- } while(true);
- }
- fclose(exp);
- printf("Data saved!\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement