Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. int incr = STRLEN;
  2.                 exp = fopen(MY_FILE, "a");
  3.  
  4.                 if(file == NULL){
  5.                     printf(ERROR);
  6.                 }
  7.                 else{
  8.                     char end[] = "STOP";
  9.                     int type = 1;
  10.  
  11.                     do{
  12.                         char *str = (char *)malloc(STRLEN * sizeof(char));
  13.                         printf("Enter string: ");
  14.                         fgets(str, incr, stdin);
  15.  
  16.                         if(strncmp(str, end, 4) == 0){
  17.                             break;
  18.                         }
  19.  
  20.                         while(str[strlen(str)-1] != '\n'){
  21.                             incr = incr + STRLEN;
  22.                             char *newline = (char *)realloc(str, incr * sizeof(char));
  23.  
  24.                             str = newline;
  25.                             fgets(str+strlen(str), STRLEN, stdin);
  26.                         }
  27.                         str[strlen(str)- 2] = '\0';
  28.  
  29.                         fprintf(exp,"%d;%s\n",type, str);
  30.  
  31.                         free(str);
  32.  
  33.                     } while(true);
  34.                 }
  35.                 fclose(exp);
  36.                 printf("Data saved!\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement