strcmp between pointer value and user input problem

This is a discussion on strcmp between pointer value and user input problem within the C++ Programming forums, part of the General Programming Boards category; Hello All, im trying to get some user input, compare it to the data stored in a .dat file and ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    22

    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:
    Code:
         cout<<"\nPlease Enter the Department You Wish to View: ";
         cin>>dept;
         
         while(i < counter)
         {   
            indata.seekg(i * size, ios::beg);
            indata.read (reinterpret_cast<char *> (&unistaff),
                                sizeof(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?

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

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21