zero_shubham1

got_solution

Jul 25th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct str_in{
  6.     char str[100];
  7.     int num;
  8.     };
  9.  
  10. int main()
  11. {
  12.     struct str_in str_in_ar[3];
  13.     int i;
  14.     FILE *fp;
  15.  
  16.     for(i=0;i<3;i++)
  17.     {
  18.         printf("Enter a string(100 character limit): ");
  19.         fflush(stdin);
  20.         gets(str_in_ar[i].str);
  21.         printf("Enter a number: ");
  22.         fflush(stdin);
  23.         scanf("%d",&str_in_ar[i].num);
  24.     }
  25.  
  26.     printf("Writing it to file.....");
  27.  
  28.     fp = fopen("str_55.txt","a");
  29.     if(fp)
  30.     {
  31.         for(i=0;i<3;i++)
  32.         {
  33.             fprintf(fp,"%s : %d\n",str_in_ar[i].str,str_in_ar[i].num);
  34.         }
  35.         fclose(fp);
  36.     }
  37.  
  38.     return 0;
  39. }
Add Comment
Please, Sign In to add comment