zero_shubham1

code_crashed

Jul 20th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 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.     char ap_str[200];
  15.     FILE *fp;
  16.  
  17.     for(i=0;i<3;i++)
  18.     {
  19.         printf("Enter a string(100 character limit): ");
  20.         fflush(stdin);
  21.         gets(str_in_ar[i].str);
  22.         printf("Enter a number: ");
  23.         fflush(stdin);
  24.         scanf("%d",&str_in_ar[i].num);
  25.     }
  26.  
  27.     printf("Writing it to file.....");
  28.  
  29.     fp = fopen("str_1.txt","a");
  30.     if(fp)
  31.     {
  32.         for(i=0;i<3;i++)
  33.           strcpy(ap_str,str_in_ar[i].str);
  34.           strcat(ap_str, " ");
  35.           strcat(ap_str, (char)str_in_ar[i].num);
  36.           //strcat(ap_str, "\n");
  37.           fputs(ap_str,fp);
  38.           memset(ap_str,0,200);
  39.         fclose(fp);
  40.     }
  41.  
  42.     return 0;
  43. }
Add Comment
Please, Sign In to add comment