title: printing and scanning files in c
body: <p>I'm writing a program in c with a file of names and numbers. the user inputs a number and then it should print out the name beside it. the file looks something like this... </p>
  
  <pre><code>154 Sam
  245 Jane
  345 Joe
  </code></pre>
  
  <p>Im not sure how to only print certain words from the file after matching the input from the user, but i do know when i use fgets and fscanf it printd the whole file</p>
  
  <p>so far i have </p>
  
  <pre><code>FILE *pf;
  pf = fopen("C:\\Sample.text", "a+");
  char str[200];
  char input2[10];
  printf("\nPlease enter a number:");
  scanf("%s", &amp;input2);`
  
  while(!feof(pf))
  {
      fscanf(pf,"%s/n",str);
  
      if (strcmp(str,input2)==0)
      {
          printf("The First name is %s\n",fgets(str,10,pf));
      }
  }
  </code></pre>