Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 07-22-2005, 12:47 PM   #1 (permalink)
slashdot
Registered User
 
Join Date: Dec 2004
Posts: 43
slashdot is on a distinguished road
SDL program problem...

This program doesn't compile right... I believe its because it doesn't have a proper return 0; at the end. But when I put it at the end, it gives me the same error. (error at bottom)
Code:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <SDL/SDL.h> 
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
	if(SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr, "Could not initialize SDL: %s\n",
				SDL_GetError());
			return -1;
}

atexit(SDL_Quit);

SDL_Surface* screen;
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_ANYFORMAT);
if( !screen ) {
	fprintf(stderr, "Couldn't create a surface: %s\n",
			SDL_GetError());
	return -1;
}
Quote:
ERROR:
anyone@george's:~$ g++ -s SDLBLECH.cpp -o SDLBLECH `sdl-config --libs --cflags`
SDLBLECH.cpp: In function `int main(int, char**)':
SDLBLECH.cpp:26: error: parse error at end of input
anyone@george's:~$
How would I fix this problem? I am just playing with SDL to understand it better, just if you want to know what I was doing.
slashdot is offline   Reply With Quote
Old 07-22-2005, 12:57 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
Here is your problem:
Code:
int main(int nNumberofArgs, char* pszArgs[])
{
	if(SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr, "Could not initialize SDL: %s\n",
				SDL_GetError());
			return -1;
}
You missed a ending } for your if() statement.
This should be better:
Code:
int main(int nNumberofArgs, char* pszArgs[])
{
	if(SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr, "Could not initialize SDL: %s\n",
				SDL_GetError());
			return -1;
             }
      return 0;
}
Altho the ending part of it, dosn't make any sence
Code:
atexit(SDL_Quit);

SDL_Surface* screen;
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_ANYFORMAT);
if( !screen ) {
	fprintf(stderr, "Couldn't create a surface: %s\n",
			SDL_GetError());
	return -1;
}
is left floating in mid air. You are not allowed to have an if() statement standing alone, it must be encapsulated by some form of function, from where you can activate that code in the simple function call elsewhere in your code. If I were you, I would merge that with the main() function, so entire code would be something like this:
Code:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <SDL/SDL.h> 
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    if(SDL_Init(SDL_INIT_VIDEO) < 0 ) {
        fprintf(stderr, "Could not initialize SDL: %s\n",SDL_GetError());
        return -1;
    }
    atexit(SDL_Quit);
    SDL_Surface* screen;
    screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_ANYFORMAT);
    if( !screen ) {
        fprintf(stderr, "Couldn't create a surface: %s\n", SDL_GetError());
        return -1;
    }
    return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 07-22-2005, 01:51 PM   #3 (permalink)
slashdot
Registered User
 
Join Date: Dec 2004
Posts: 43
slashdot is on a distinguished road
Using your example I get this error...

anyone@george's:~$ g++ -s SDLBLECH.cpp -o SDLBLECH `sdl-config --libs --cflags`
SDLBLECH.cpp:1: error: parse error before `=' token
SDLBLECH.cpp:1: error: parse error before `#' token
In file included from /usr/include/c++/3.3.4/cstdlib:50,
from SDLBLECH.cpp:2:
/usr/include/c++/3.3.4/cstddef:52: error: `ptrdiff_t' not declared
anyone@george's:~$ ls
slashdot is offline   Reply With Quote
Old 07-22-2005, 05:30 PM   #4 (permalink)
slashdot
Registered User
 
Join Date: Dec 2004
Posts: 43
slashdot is on a distinguished road
AH! I got it to work...

Code:
{
	SDL_Surface *screen;

	printf("Initializing SDL!\n");

	if((SDL_Init(SDL_INIT_VIDEO)==-1))
	{
		printf("Could not initialize SDL: %s\n: SDL_GetError()");
			exit(-1);
	}

	screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);	
	if ( screen == NULL )
	{
		fprintf(stderr, "Couldn't set 640x480 video mode: %s\n", SDL_GetError());
		exit(1);
	}
Thanx for the help though.. you put in the right direction.

Last edited by Valmont; 07-23-2005 at 09:45 AM.
slashdot is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hashing problem jodders Standard C, C++ 1 02-09-2005 01:51 PM
Mark Reader Problem gamehead200 Standard C, C++ 11 11-14-2004 06:08 AM
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
c simple question problem with switch case if13121 Standard C, C++ 1 10-24-2004 09:43 PM
Problem with Mortgage.cpp verdell32 Standard C, C++ 7 10-23-2004 06:50 AM


All times are GMT -8. The time now is 03:55 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting