Thread: Undeclared identifier error

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230

    Undeclared identifier error

    Hi, I'm getting the following error:

    Error 1 error C2065: 'szGatewayServer' : undeclared identifier


    Code:
    #define SERVER "test"
    
    struct sTransactionDetails {
    	char szGatewayServer[70];
    };
    
    int ConnectToGateway(int sockfd, char * szGatewayServer);
    
    int main(void) {
       	int sockfd;     
    	struct sTransactionDetails txnDetails;
    	memset(&txnDetails, 0, sizeof(txnDetails));
    	
    	sockfd = CreateSocket();
    
    	strncpy_s(txnDetails.szGatewayServer, sizeof(txnDetails.szGatewayServer), SERVER, strlen(SERVER));
    	ConnectToGateway(sockfd, txnDetails.szGatewayServer);
    	return 0;
    }
    
    
    int ConnectToGateway(int sockfd, char * szGatwayServer) {
    	struct sockaddr_in hints;
    	int state;
    	struct hostent * hostStruct;
    	char ** palias;
    
    	hostStruct = gethostbyname(szGatewayServer);
    
    	for (palias = hostStruct->h_addr_list; *palias != 0; palias++)
    		printf("Host: %s\n", *palias);
    
    	state = connect(sockfd, (const struct sockaddr *)&hints, sizeof hints);
    	if (state == SOCKET_ERROR)
    		return SOCKET_ERROR;
    
    	return 0;
    }
    This is the line where the error is occuring:

    Code:
    hostStruct = gethostbyname(szGatewayServer);
    I don't understand why I'm getting this error... It's more than likely something stupid I can't see but I've been searching for it for like 30 minutes now... Any ideas?

    I've chopped out lots of unnecessary code to try and make it easier to read.

    Thanks.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You don't have a variable of that name declared. You do have a szGatwayServer, but that's it.

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Good lord. I can't believe I didn't see that. I even rechecked it for that exact reason and still missed it... This is why it helps to have a fresh perspective Thanks tabstop!
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM