#include <stdio.h>
#include <string.h>
#include <SDL_net.h>
/* Hostname and port */
char *hostname = "eternal-lands.solexine.fr";
int port = 2000;
/* Ip address */
IPaddress ipaddress;
/* Socket */
TCPsocket tcpsock;
/* Username and Password */
char *Username = "robocop";
char *Password = "changedovbiously";
int main()
{
int len, result;
char *temp;
/* Start up SDL and SDL_NET */
if(SDL_Init(0) == -1)
{
printf("Couldnt start SDL up");
exit(1);
}
if(SDLNet_Init() == -1)
{
printf("Couldnt start SDL_NET up");
exit(2);
}
/* Get the ip address from hostname */
if (SDLNet_ResolveHost(&ipaddress, hostname, port) == -1)
{
printf("Couldnt resolve ip address from hostame");
exit(1);
}
/* Open the connection */
TCPsocket = SDLNet_TCP_Open(&IPaddress);
if(tcpsock != 0)
{
printf("Could not connect");
exit(2);
}
/* Login - Send Username */
strcpy(temp, "140 ");
strcat(temp, Username);
len = strlen(temp) + 1;
result = SDLNet_TCP_Send(TCPsocket, temp, len);
if(result < len)
{
printf("Didnt manage to send Username");
}
/* Login - Send Password */
strcpy(temp, "140 ");
strcat(temp, Password);
len = strlen(temp) + 1;
result = SDLNet_TCP_Send(TCPsocket, temp, len);
if(result < len)
{
printf("Didnt manage to send Password");
}
/* Close the connection and shutdown SDL_NET*/
SDLNet_TCP_Close(TCPsocket);
SDLNet_Quit();
}
🔒 Locked
Wierd error with my code
Advertisement
Original Post
edit: added tags and i forgot to say, this is in c. edit2: i have done the protocol wrong and things so this code wont work properly, but i have fixed that, the problem is just with the error. Im trying to write a simple program to connect to a online game i play. Bit new to it all so the mistakes are probably silly. This is the odd error i get "botattempt.c:20: error: number of arguments doesn't match prototype" Here is my code so far..
/* Open the connection */TCPsocket = SDLNet_TCP_Open(&IPaddress);if(tcpsock != 0) { printf("Could not connect"); exit(2);}looks as though the first line should be
tcpsock = SDLNet_TCP_Open(&ipaddress);
You were passing types instead of variables. Same later as well.
Good point *slaps self*
Still getting that wierd error though.. here are the errors im getting at the moment.
and here is my new and "improved" code.
Still getting that wierd error though.. here are the errors im getting at the moment.
Quote:
botattempt.c: In function `SDL_main':
botattempt.c:20: error: number of arguments doesn't match prototype
SDL_main.h:54: error: prototype declaration
and here is my new and "improved" code.
#include <stdio.h>#include <string.h>#include <SDL_net.h> /* Hostname and port */char *hostname = "eternal-lands.solexine.fr";int port = 2000;/* Ip address */IPaddress ipaddress;/* Socket */TCPsocket tcpsock; /* Username and Password */char *Username = "robocop";char *Password = "rememberedagain";int main(){ int len, result; char *temp; /* Start up SDL and SDL_NET */ if(SDL_Init(0) == -1) { printf("Couldnt start SDL up"); exit(1); } if(SDLNet_Init() == -1) { printf("Couldnt start SDL_NET up"); exit(2); } /* Get the ip address from hostname */ if (SDLNet_ResolveHost(&ipaddress, hostname, port) == -1) { printf("Couldnt resolve ip address from hostame"); exit(1); } /* Open the connection */ tcpsock = SDLNet_TCP_Open(&ipaddress); if(tcpsock != 0) { printf("Could not connect"); exit(2); } /* Send login packet */ strcpy(temp, "140 "); strcat(temp, Username); strcat(temp, " "); strcat(temp, Password); len = strlen(temp) + 1; result = SDLNet_TCP_Send(tcpsock, temp, len); if(result < len) { printf("Didnt manage to send Login message"); } /* Close the connection and shutdown SDL_NET*/ SDLNet_TCP_Close(tcpsock); SDLNet_Quit();}
Don't know about SDL.
Does it replace main with SDL_main, or something?
Maybe you should use:
int main(int argc, char* argv[])
Does it replace main with SDL_main, or something?
Maybe you should use:
int main(int argc, char* argv[])
Looking here it looks as though this is exactly what you need to do:
/* The application's main() function must be called with C linkage, and should be declared like this:#ifdef __cplusplus extern "C"#endif int main(int argc, char *argv[]) { } */
Your right it fixed the wierd error, now i get a few others. Thing is i dont understand why it fixed it! Anyway here are the errors.
Thanks for the help by the way!
And the code so far..
Thanks for the help by the way!
Quote:
[Linker error] undefined reference toSDL_Init'SDLNet_Init'
[Linker error] undefined reference to
[Linker error] undefined reference toSDLNet_ResolveHost'SDLNet_TCP_Open'
[Linker error] undefined reference to
[Linker error] undefined reference toSDLNet_TCP_Send'SDLNet_TCP_Close'
[Linker error] undefined reference to
[Linker error] undefined reference toSDLNet_Quit'WinMain@16'
[Linker error] undefined reference to
And the code so far..
#include <stdio.h>#include <string.h>#include <SDL_net.h> /* Hostname and port */char *hostname = "eternal-lands.solexine.fr";int port = 2000;/* Ip address */IPaddress ipaddress;/* Socket */TCPsocket tcpsock; /* Username and Password */char *Username = "robocop";char *Password = "gullible";int main(int argc, char *argv[]){ int len, result; char *temp; /* Start up SDL and SDL_NET */ if(SDL_Init(0) == -1) { printf("Couldnt start SDL up"); exit(1); } if(SDLNet_Init() == -1) { printf("Couldnt start SDL_NET up"); exit(2); } /* Get the ip address from hostname */ if (SDLNet_ResolveHost(&ipaddress, hostname, port) == -1) { printf("Couldnt resolve ip address from hostame"); exit(1); } /* Open the connection */ tcpsock = SDLNet_TCP_Open(&ipaddress); if(tcpsock != 0) { printf("Could not connect"); exit(2); } /* Send login packet */ strcpy(temp, "140 "); strcat(temp, Username); strcat(temp, " "); strcat(temp, Password); len = strlen(temp) + 1; result = SDLNet_TCP_Send(tcpsock, temp, len); if(result < len) { printf("Didnt manage to send Login message"); } /* Close the connection and shutdown SDL_NET*/ SDLNet_TCP_Close(tcpsock); SDLNet_Quit();}
A linker error means that you haven't specified the libraries that the linker needs to build your application. Let it know about the SDL library and it will work.
Quote:
Original post by kzar
Thing is i dont understand why it fixed it!
Whenever you are using SDL main must be declared as int main( int, char** ) or else you will generate those same errors. As the above posters have mentioned, linker errors can mean you haven't added a .lib file to your project. You'll also need the .dll files for SDL in your main project's folder to run it as well.
ok I tried the lines to include libs. It didnt change the errors but i probably did it wrong! heres me code just to make sure i got the right idea.
#include <stdio.h>#include <string.h>#include <SDL_net.h>/* Includes the SDL librarys */#pragma comment(lib, "SDL")#pragma comment(lib, "SDLmain")#pragma comment(lib, "SDLnet") /* Hostname and port */char *hostname = "eternal-lands.solexine.fr";int port = 2000;/* Ip address */IPaddress ipaddress;/* Socket */TCPsocket tcpsock; /* Username and Password */char *Username = "robocop";char *Password = "imstupid";int main(int argc, char *argv[]){ int len, result; char *temp; /* Start up SDL and SDL_NET */ if(SDL_Init(0) == -1) { printf("Couldnt start SDL up"); exit(1); } if(SDLNet_Init() == -1) { printf("Couldnt start SDL_NET up"); exit(2); } /* Get the ip address from hostname */ if (SDLNet_ResolveHost(&ipaddress, hostname, port) == -1) { printf("Couldnt resolve ip address from hostame"); exit(1); } /* Open the connection */ tcpsock = SDLNet_TCP_Open(&ipaddress); if(tcpsock != 0) { printf("Could not connect"); exit(2); } /* Send login packet */ strcpy(temp, "140 "); strcat(temp, Username); strcat(temp, " "); strcat(temp, Password); len = strlen(temp) + 1; result = SDLNet_TCP_Send(tcpsock, temp, len); if(result < len) { printf("Didnt manage to send Login message"); } /* Close the connection and shutdown SDL_NET*/ SDLNet_TCP_Close(tcpsock); SDLNet_Quit();} Quote:
Original post by Anonymous Poster
You need to make sure that you are including the right libraries. Either add SDL.lib SDLmain.lib and SDLnet.lib to your library includes in your project files, or add these lines:
#pragma comment(lib, "SDL")
#pragma comment(lib, "SDLmain")
#pragma comment(lib, "SDLnet")
That only works if you're using Microsoft C++. From the error messages he's getting he's obviously using a different compiler.
You need to add the libraries to your project or make file or whatever you are using. Check your documentation.
I just download dev-c++ to look at what documentation you have available to you:
Go to
Help->Help on Dev++
then
Dev-C++ 5->Basic Steps->Managing Project Options->Linking libraries with your project
I'm probably being too helpful here and going against my better nature - RTFM
Go to
Help->Help on Dev++
then
Dev-C++ 5->Basic Steps->Managing Project Options->Linking libraries with your project
I'm probably being too helpful here and going against my better nature - RTFM
cool right well i read the flippin manual heh. made me a project, added the stuff for the librarys, got it to compile. When i run it however it just finishes instantly and doesnt look at the code. (i put a printf in just to check and it didnt display)
I have probably messed up the project somehow :o
At least it compiles though! wouldnt have managed it on my own either, so thanks for the advice everyone.
I have probably messed up the project somehow :o
At least it compiles though! wouldnt have managed it on my own either, so thanks for the advice everyone.
You're, actually, very welcome.
ok it is running its just i didnt notice this
http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/tut1
Quote:
One last thing: when you do printf(...) when having the SDL stuff in the project options in Dev-C++ the output of printf is written to a file called stdout.txt, not the screen.
http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/tut1
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement