0
 fp= fopen("Quiz.txt", "r");
             fflush(stdin);
            printf("Enter Name To Search:");
            gets(srch);

            if(srch==std[i].name)
            {
                 printf("\n Student Name: %s", std[i].name);
                 printf("\n Roll Number :%d", std[i]. roll);
                 printf("\n First Quiz Marks :%d", std[i]. quiz1);
                 printf("\n Second Quiz Marks :%d", std[i]. quiz2);
                 printf("\n Third Quiz Marks :%d", std[i]. quiz3);
                 printf("\n Fourth  Quiz Marks :%d", std[i]. quiz4);
                 printf("\n Fifth Quiz Marks :%d", std[i]. quiz5);
            }
            else{
                printf("No Data Of %s", srch);
            }
            getchar();
            fclose(fp);

I am not getting data related to search that user search suppose if user search their name if the name is available in a file then it returns with users name roll number and 5 quiz marks if not then return no data available

false
  • 10,264
  • 13
  • 101
  • 209
  • 2
    First of all, never ***ever*** use the `gets` function! It's [a dangerous function](https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used) and because of that have been removed from the C standard. Use e.g. [`fgets`](https://en.cppreference.com/w/c/io/fgets) instead (but beware of its differences from `gets`). Secondly, passing an input-only stream to `fflush` (like `stdin`) is explicitly mentioned as *undefined behavior* by the C specification. – Some programmer dude Jan 05 '19 at 05:18
  • As for (what I think is) your problem, I suggest you get a book or two to read, because just about any book or tutorial (even pretty bad ones) should have told you how to compare strings. – Some programmer dude Jan 05 '19 at 05:19
  • You *cannot* compare string equality in C with `if(srch==std[i].name)`. See [strcmp(3) - Linux manual page](http://man7.org/linux/man-pages/man3/strcmp.3.html) or [strcmp, wcscmp, _mbscmp | Microsoft Docs](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strcmp-wcscmp-mbscmp) -- your choice. – David C. Rankin Jan 09 '19 at 02:23

1 Answers1

0

for string comparison, you have the possibility to use the function int strcmp(const char *s1, const char *s2);. The strcmp function returns 0 if and only if the two strings are identical. The returned value is negative if the first string is greater than the second and positive if it is not. (don't forget to include the header #include <string.h>)

sambia39
  • 35
  • 9