title: Add feature searching data values with arrays (type char) in C
body: <p>So I make C programs (making database with array), combined from all post in this forum, which has <strong>Create, Display, Update, Delete &amp; Search</strong> function, but when <em><strong>update, delete, search</strong></em> the data, it can only be done via <strong>int values</strong> which in my variable is <strong>absen</strong> or in English is <strong>ID number</strong></p>
  <p>I want to add feature to this program which can also <em><strong>search</strong></em> the data by string value, which in my variable is <strong>nama, alamat &amp; nohp</strong> or in English is <strong>Name, Address &amp; Phone number</strong>, and that code located in <em><strong>void search()</strong></em></p>
  <p>Any and all help is appreciated.
  Here is my full code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  //FUNGSI MENDEKLARASIKAN STRUKTUR DATA
  struct data
  {
   int absen;
   char nama[30], alamat[30], nohp[30];
  
  }dat;
  //FUNGSI MEMASUKKAN DATA
  void insert()
  {
   FILE *fp;
   fp = fopen(&quot;Record&quot;, &quot;a&quot;);
   printf(&quot;Masukkan nomor absen yg di inginkan : &quot;);
   scanf(&quot;%d&quot;, &amp;dat.absen);
   printf(&quot;Masukkan Nama      : &quot;);
   scanf(&quot;%s&quot;, &amp;dat.nama);
   printf(&quot;Masukkan Alamat    : &quot;);
   scanf(&quot;%s&quot;, &amp;dat.alamat);
    printf(&quot;Masukkan No Hp     : &quot;);
   scanf(&quot;%s&quot;, &amp;dat.nohp);
   fwrite(&amp;dat, sizeof(dat), 1, fp);
   fclose(fp);
  }
  //FUNGSI MENAMPILKAN DATA
  void disp()
  {
   FILE *fp1;
   fp1 = fopen(&quot;Record&quot;, &quot;r&quot;);
   printf(&quot;\nNo Absen\tNama\tAlamat\tNo HP\n\n&quot;);
   while (fread(&amp;dat, sizeof(dat), 1, fp1))
   printf(&quot;  %d\t\t%s\t%s\t%s\n&quot;, dat.absen, dat.nama, dat.alamat, dat.nohp);
   fclose(fp1);
  }
  //FUNGSI MENCARI DATA (BERDASARKAN ABSEN)
  void search()
  {
   FILE *fp2;
   int r, s, avl;
   printf(&quot;\nMasukkan nomor absen yg ingin dicari  :&quot;);
   scanf(&quot;%d&quot;, &amp;r);
   avl = avlabsen(r);
   if (avl == 0)
    printf(&quot;No absen %d tidak ada dalam database\n&quot;,r);
   else
   {
    fp2 = fopen(&quot;Record&quot;, &quot;r&quot;);
    while (fread(&amp;dat, sizeof(dat), 1, fp2))
    {
     s = dat.absen;
     if (s == r)
     {
      printf(&quot;\nNo absen = %d&quot;, dat.absen);
      printf(&quot;\nNama    = %s&quot;, dat.nama);
      printf(&quot;\nAlamat  = %s&quot;, dat.alamat);
      printf(&quot;\nNo HP   = %s\n&quot;, dat.nohp);
      
     }
    }
    fclose(fp2);
   }
  }
  //FUNGSI MENGHAPUS DATA (BERDASARKAN ABSEN)
  
  
  void deletefile()
  {
   FILE *fpo;
   FILE *fpt;
   int r, s;
   printf(&quot;Masukkan nomor absen yg ingin dihapus :&quot;);
   scanf(&quot;%d&quot;, &amp;r);
   if (avlabsen(r) == 0)
    printf(&quot;No absen %d tidak ada dalam database\n&quot;, r);
   else
   {
    fpo = fopen(&quot;Record&quot;, &quot;r&quot;);
    fpt = fopen(&quot;TempFile&quot;, &quot;w&quot;);
    while (fread(&amp;dat, sizeof(dat), 1, fpo))
    {
     s = dat.absen;
     if (s != r)
      fwrite(&amp;dat, sizeof(dat), 1, fpt);
    }
    fclose(fpo);
    fclose(fpt);
    fpo = fopen(&quot;Record&quot;, &quot;w&quot;);
    fpt = fopen(&quot;TempFile&quot;, &quot;r&quot;);
    while (fread(&amp;dat, sizeof(dat), 1, fpt))
     fwrite(&amp;dat, sizeof(dat), 1, fpo);
  
    printf(&quot;\n&gt;&gt;&gt;DATA TERHAPUS&lt;&lt;&lt;\n&quot;);
    fclose(fpo);
    fclose(fpt);
   }
  
  }
  //FUNGSI MENGUPDATE DATA (BERDASARKAN ABSEN)
  void update()
  {
   int avl;
   FILE *fpt;
   FILE *fpo;
   int s, r, ch;
   printf(&quot;Masukkan no absen yg ingin di update:&quot;);
   scanf(&quot;%d&quot;, &amp;r);
   avl = avlabsen(r);
   if (avl == 0)
   {
    printf(&quot;No absen %d tidak ada dalam database&quot;, r);
   }
   else
   {
    fpo = fopen(&quot;Record&quot;, &quot;r&quot;);
    fpt = fopen(&quot;TempFile&quot;, &quot;w&quot;);
    while (fread(&amp;dat, sizeof(dat), 1, fpo))
    {
     s = dat.absen;
     if (s != r)
      fwrite(&amp;dat, sizeof(dat), 1, fpt);
     else
     {
      printf(&quot;\n\t1. Update Nama dari no absen %d&quot;, r);
      printf(&quot;\n\t2. Update Alamat dari no absen %d&quot;, r);
      printf(&quot;\n\t3. Update No Hp dari no absen %d&quot;, r);
      printf(&quot;\n\t4. Update Nama, Alamat dan no HP dari no absen %d&quot;, r);
      printf(&quot;\nEnter your choice:&quot;);
      scanf(&quot;%d&quot;, &amp;ch);
      switch (ch)
      {
      case 1:
       printf(&quot;Masukkan Nama:&quot;);
       scanf(&quot;%s&quot;, &amp;dat.nama);
       break;
      case 2:
       printf(&quot;Masukkan Alamat : &quot;);
       scanf(&quot;%s&quot;, &amp;dat.alamat);
       break;
      case 3:
       printf(&quot;Masukkan No HP: &quot;);
       scanf(&quot;%s&quot;, &amp;dat.nohp);
       break;
      case 4:
       printf(&quot;Masukkan Name: &quot;);
       scanf(&quot;%s&quot;, &amp;dat.nama);
       printf(&quot;Masukkan Alamat: &quot;);
       scanf(&quot;%s&quot;, &amp;dat.alamat);
       printf(&quot;Masukkan No HP: &quot;);
       scanf(&quot;%s&quot;, &amp;dat.nohp);
       break;
      default:
       printf(&quot;Pilihan SALAH&quot;);
       break;
      }
      fwrite(&amp;dat, sizeof(dat), 1, fpt);
     }
    }
    fclose(fpo);
    fclose(fpt);
    fpo = fopen(&quot;Record&quot;, &quot;w&quot;);
    fpt = fopen(&quot;TempFile&quot;, &quot;r&quot;);
    while (fread(&amp;dat, sizeof(dat), 1, fpt))
    {
     fwrite(&amp;dat, sizeof(dat), 1, fpo);
    }
    fclose(fpo);
    fclose(fpt);
  
    printf(&quot;\n&gt;&gt;&gt;DATA TERUPDATE&lt;&lt;&lt;\n&quot;);
   }
  }
  
  //FUNGSI MENGECEK DATA (BERDASARKAN ABSEN)//
  int avlabsen(int abs)
  {
   FILE *fp;
   int c = 0;
   fp = fopen(&quot;Record&quot;, &quot;r&quot;);
   while (!feof(fp))
   {
    fread(&amp;dat, sizeof(dat), 1, fp);
  
    if (abs == dat.absen)
    {
     fclose(fp);
     return 1;
    }
   }
   fclose(fp);
   return 0;
  }
  //FUNGSI MENGECEK DATA KOSONG ATAU TIDAK
  int empty()
  {
   int c = 0;
   FILE *fp;
   fp = fopen(&quot;Record&quot;, &quot;r&quot;);
   while (fread(&amp;dat, sizeof(dat), 1, fp))
    c = 1;
   fclose(fp);
   return c;
  }
  // PROGRAM UTAMA
  void main()
  {
   int c, emp;
   do
   {
    printf(&quot;\n\t---Silahkan Pilih---------\n&quot;);
    printf(&quot;\n\t1. MASUKKAN\n\t2. TAMPILKAN\n\t3. CARI&quot;);
    printf(&quot;\n\t4. HAPUS\n\t5. UPDATE\n\t6. KELUAR PROGRAM&quot;);
  
    printf(&quot;\n\n------------------------------------------\n&quot;);
    printf(&quot;\nSilahkan Pilih: &quot;);
    scanf(&quot;%d&quot;, &amp;c);
    printf(&quot;\n&quot;);
    switch (c)
    {
    case 1:
     insert();
     break;
    case 2:
     emp = empty();
     if (emp == 0)
      printf(&quot;\nData KOSONG\n&quot;);
     else
      disp();
     break;
    case 3:
     search();
     break;
    case 4:
     deletefile();
     break;
    case 5:
     update();
     break;
    case 6:
     exit(1);
     break;
    default:
     printf(&quot;\nPilihanmu salah\nSilahkan dicoba lagi...\n&quot;);
     break;
  
    }
   } while (c != 6);
  }
  </code></pre>