title: How to search for String in C language
body: <p>I am developing a student management system in C, but I can't seem to accomplish the search function. Writing to a file works fine but searching by name is not working. Nothing happens when I enter the name and the program exits.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct student {
      int id;
      char name[10];
      int semester;
  };
  
  int main(void) {
      char name[10], c[100];
      struct student s;
      FILE *fp;
      int choice;
  
      printf("Enter 1 to Add record\nEnter 2 to Search \n");
      scanf("%d", &amp;choice);
  
      switch(choice) {
          case 1:
              fp = fopen("std.txt", "a");
              printf("\nEnter id: ");
              scanf("%d", &amp;s.id);
              fflush(stdin);
              printf("\nEnter name: ");
              scanf("%s", &amp;s.name);
              fflush(stdin);
              printf("\nEnter semester: ");
              scanf("%d", &amp;s.semester);
              fflush(stdin);
  
              fprintf(fp, "\nId: %d\tName: %s\tSemester: %d\n", s.id,s.name,s.semester);
              fclose(fp);
              break;
  
          case 2:
              fp=fopen("std.txt","r");
              printf("ENTER THE NAME ");
              scanf("%s",&amp;name);
              while(feof(fp)) {
                  if(strcmp(name, s.name) == 0) {
                      printf("\n\t%d\t %s\t %d", s.id, s.name, s.semester);
                      getch();
                      break;
                  }
              }
              fclose(fp);
              getch();
              break;
  
          case 3:
              exit(1);
      }
      getchar();
  } 
  </code></pre>