Thread: strcmp between pointer value and user input problem

  1. #1
    Registered User
    Join Date
    Aug 2007

    strcmp between pointer value and user input problem

    Hello All,

    im trying to get some user input, compare it to the data stored in a .dat file and output all the information for the contact if the user input matches the data of the contact in the dat file. Here is a segment of my code:
         cout<<"\nPlease Enter the Department You Wish to View: ";
         while(i < counter)
            indata.seekg(i * size, ios::beg);
   (reinterpret_cast<char *> (&unistaff),
            if (strcmp(universitystaff->department) == (dept))
    it gives me an error message and opens the string.h file. I tryed without strcmp a couple of ways i know but it just didnt work, any ideas?

    Last edited by Salem; 03-31-2008 at 11:39 AM. Reason: Learn how to use [code][/code] tags

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    You should rather use std::string than char arrays.
    The problem is that you need to re-look at the documentation for strcmp. It takes two arguments and returns < 0, 0 or > 0. Take a look again.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed