Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <sys/stat.h>
- struct answers_1{
- char* ans;
- };
- struct answers_1 get_file_name(char *path, int x);
- int main (void)
- {
- struct answers_1 answers;
- char* path = (char*) malloc( 256 );
- long long x = 0;
- printf("Input file name:\n");
- scanf("%s",path);
- printf("Input X:\n");
- scanf("%lld", &x);
- answers = get_file_name(path,x);
- printf("%s ", answers.ans);
- }
- struct answers_1 get_file_name(char *path, int x){
- struct answers_1 answersf;
- answersf.ans = "NO";
- FILE *in;
- in = fopen(path, "r");
- if (in == NULL) {
- exit(1);
- }
- long long buf=0;
- while ((fscanf(in, "%lld", &buf)!=EOF)) {
- if(buf==x)
- answersf.ans = "Yes";
- }
- fclose(in);
- return answersf;
- }
Advertisement
Add Comment
Please, Sign In to add comment