Kosty_Fomin

Untitled

Nov 28th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <sys/stat.h>
  5.  
  6. struct answers_1{
  7.     char* ans;
  8. };
  9.  
  10. struct answers_1  get_file_name(char *path, int x);
  11.  
  12.  
  13. int main (void)
  14. {
  15.     struct answers_1  answers;
  16.     char* path = (char*) malloc( 256 );
  17.     long long x = 0;
  18.    
  19.     printf("Input file name:\n");
  20.     scanf("%s",path);
  21.     printf("Input X:\n");
  22.     scanf("%lld", &x);
  23.    
  24.     answers = get_file_name(path,x);
  25.    
  26.    
  27.     printf("%s ", answers.ans);
  28.    
  29. }
  30.  
  31.  
  32.  
  33.  
  34. struct answers_1  get_file_name(char *path, int x){
  35.    
  36.     struct answers_1  answersf;
  37.     answersf.ans = "NO";
  38.     FILE *in;
  39.     in = fopen(path, "r");
  40.    
  41.     if (in == NULL) {
  42.         exit(1);
  43.     }
  44.    
  45.     long long buf=0;
  46.    
  47.    
  48.     while ((fscanf(in, "%lld", &buf)!=EOF)) {
  49.         if(buf==x)
  50.             answersf.ans = "Yes";
  51.        
  52.     }
  53.  
  54.     fclose(in);
  55.     return answersf;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment