more debugging

This is a discussion on more debugging within the C++ Programming forums, part of the General Programming Boards category; C:\Borland\BCC55\src>bcc32 golfh.cpp golfm.cpp golff.cpp Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland golfh.cpp: golfm.cpp: golff.cpp: Error E2277 golff.cpp ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    52

    more debugging

    C:\Borland\BCC55\src>bcc32 golfh.cpp golfm.cpp golff.cpp
    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    golfh.cpp:
    golfm.cpp:
    golff.cpp:
    Error E2277 golff.cpp 25: Lvalue required in function setgolf(golf &,const char *,int)

    I assume this means the types dont match in the line
    g.fullname=name //????

    Warning W8057 golff.cpp 27: Parameter 'name' is never used in function setgolf(g
    olf &,const char *,int)
    *** 1 errors in Compile ***
    Code:
    #include <iostream>
    #include "golfh.cpp"
    using namespace std;
    
    int setgolf(golf & g)
    {
    	cout << "Enter golfers name:";
    	cin.get(g.fullname,Len);
    	if (cin)
    	{
    		return 0;
    	}
    	else
    	{
    		cout << "Enter player's handicap:";
    		cin >> g.handicap;
    		return 1;
    	}
    
    }
    
    
    void setgolf(golf & g, const char *name, int hc)
    {
    	g.fullname=name;// error here ????
    	g.handicap=hc;
    }
    
    void handicap(golf & g, int hc)
    {
    	g.handicap=hc;
    }
    void showgolf(const golf & g)
    {
    	cout << "Player's name:"<<g.fullname<<endl;
    	cout << "Handicap:"<<g.handicap<<endl;
    	cout << endl;
    }

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > Warning W8057 golff.cpp 27: Parameter 'name' is never used in function setgolf(golf &,const char *,int)

    That means you declare "name" as a parameter, but don't use it in the function.

    What's your golf struct?

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    52

    header file

    Here is the header file with the struct and prototypes
    Code:
    //golff.h	for 8.3 pg 369 c++ primer plus
    const int Len=40;
    struct golf
    {
    	char fullname[Len];
    	int handicap;
    };
    
    int setgolf(golf & g);
    void setgolf(golf & g, const char *name, int hc);
    void handicap(golf & g, int hc);
    void showgolf(const golf & g);

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Never mind - I looked it up.

    use strcpy in place of

    g.fullname=name;// error here ????

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    52

    main file

    Here is the main file
    Code:
    #include <iostream>
    #include "golfh.cpp"
    using namespace std;
    
    
    
    int main()
    {
    	const int Max=20;
    	golf folf[Max];
    	int end,c;
    	c=0;
    	end=1;
    	setgolf(folf[c],"Troy",40);// here is the calling function
    
    	while (end && (c<Max))
    	{
    		showgolf(folf[c]);
    		c++;
    		end=setgolf(folf[c]);
    	}
    	return 0;
    }

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    in the cpp file and the main program file it should be

    #include "golff.h"

    rather than

    #include "golff.cpp"


    use the strcpy suggestion as per GovtCheese's post.

    in setgolf() I think you might want this:

    if(!cin)
    {
    return 0;
    }

    otherwise, cin should "always" be true, so end will always be assigned the value of 0 so the while loop will only work once.
    Last edited by elad; 03-25-2002 at 02:34 PM.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    52
    It will not compile as golf.h because it assumes the header file is a c file rather than a c++ file. There is prbly a special extension for c++ headers but cpp worked fine.

    According to c++ primer plus cin should evaluate to false if the peceding line cin.get(g.fullname,Len); fails. ie by entering a blank line. I coule not get this to work so i used this instead:
    if (strlen(g.fullname)==0)

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I always get twisted up in these discussions. BUT: it is my understanding that the conditional for an if statement needs to evaluate to true for the body of the if statement to run. If cin evaluates to false when when the preceding line fails then the conditional of the if will be false if the conditional is just cin, and the body of the if statement will not run meaning end will never be zero. If cin evaluates to false when the preceding line fails, then !cin will evaluate to true and the body of the if will run. If cin in the preceding line evaluates to true then !cin will evaluate to false and the body of the if will not run if the preceding line does not fail. Therefore I still think you want !cin rather than cin as the conditional of the if statement, but if the code works as you desire, so be it.

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    52
    I think you are right conceptouallyw but neither way worked using cin or !cin hence my use of strlen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-C++: Problems with Breakpoint Debugging
    By Thileepan_Bala in forum C Programming
    Replies: 1
    Last Post: 01-17-2008, 09:48 AM
  2. Problem in debugging in Eclipse
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 08-21-2007, 09:53 AM
  3. Debugging Dev C++
    By tuurb046 in forum Tech Board
    Replies: 10
    Last Post: 08-16-2007, 12:51 PM
  4. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 07:35 PM
  5. debugging directx apps
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 08-16-2003, 08:56 AM

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