Thread: Search Problem

  1. #1
    Unregistered
    Guest

    Search Problem

    I am creating a simple search feature in a C database which is using an array.
    but i cannot understand why the following code will not find the value in the which is in the surname field of the array.

    while (temp<i+1)
    {
    if (records[temp].surname=="a") printf("TEST");

    getch();
    temp++;
    }


    i is the number of records in the array
    temp is the counter
    records is the name of the array
    with surname as the field
    the character "a" is in a record in the surname field of the array

    can any1 see the problem

    thnx

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >if (records[temp].surname=="a") printf("TEST");
    To test for a single character, use the single quotes 'a'. Double quotes means a string terminated by NUL, so you're trying to test two characters with == which won't work.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exhaustive graph search
    By Cpro in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2008, 11:08 AM
  2. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  3. binary search and search using binary tree
    By Micko in forum C++ Programming
    Replies: 9
    Last Post: 03-18-2004, 10:18 AM
  4. Binary trees search problem...
    By Umoniel in forum C Programming
    Replies: 2
    Last Post: 02-22-2004, 02:29 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM