In article <11**********************@e3g2000cwe.googlegroups. com>,
smartbeginner <rr******@gmail.comwrote:
>I cannot view in the console what all i have included in printf() .Why
this?
Code:
#include<stdio.h>
#include<conio.h>
#include "SDL/SDL.h"
Neither conio nor SDL are part of the C standard, so in this newsgroup
we do not know what they do. In particular, as you have used <conio.h>
instead of "conio.h" you would be picking up a conio.h from the
implementation's headers, and the implementation might have done
something stupid such as redefining printf().
>int main(void)
{
int x=1;
SDL_Event event;
SDL_Init(SDL_INIT_JOYSTICK );
SDL_Joystick *joy;
// Check for joystick
if(SDL_NumJoysticks()>0){
// Open joystick
joy=SDL_JoystickOpen(0);
if(joy)
{
printf("Opened Joystick 0\n");
printf("Name: %s\n", SDL_JoystickName(0));
}
SDL_Quit();
SDL_JoystickClose(joy);
return 0;
}
This is not your real code. This code would not compile. The { on
the if(SDL_NumJoysticks()>0) line matches against the } after the
return 0, and there is no matching } for the { that begins the routine.
Notice that in your code, you only use printf() if you were able to
open a Joystick (whatever that means.) The reason you do not get
any output could be as simple as you not being able to open any
joysticks.
I question whether you should really be closing a joystick *after*
you Quit SDL -- doesn't Quit mean "get out of SDL", after which
point closing a joystick would not be valid?
Your code does not use the int x, but that would not cause any problems.
I note that your code is C99, not C89: you have a function call
(to SDL_Init) before the declaration of SDL_Joystick *joy, which
would not be valid in C89. The // comments are also not valid in C89
but are a common extension. Please be aware that there are very few
fully compliant "hosted" C99 implementations available, and it is fairly
unlikely that you are using one of them. Because of the non-compliance
of the environment, your code might do things that would not be expected
according to the C99 standard, and there isn't much you can do about
that except to study in detail exactly how your environment differs
from a true C99 environment. It is safer to write in C89.
Your code appears to have platform dependancies; in particular,
it appears to be Windows specific code. After fixing the above code
issues, if you continue to have difficulty, contact a newsgroup
that deals with your platform.
[Off topic]
As you are using Windows, are you sure the console isn't simply being
closed before you have a chance to read anything on it?
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton