Results 1 to 4 of 4

Thread: c++ sdl error

  1. #1
    Join Date
    Apr 2013
    Beans
    2

    Question c++ sdl error

    Hi guys! I'm having problems with sdl-library and its keyboard event. The main idea of the program is: save char in to char array and meanwhile listen if ctrl+alt+character, then save char array to .txt file called "character (pressed one)" Or ctrl+character is pressed and read "pressed character named txt file". At the end of program loop everything is going to be saved in .txt file.

    Sorry about my variable names and my bad English, it is not my native languague =D

    My code:
    #include <unistd.h>
    #include <sstream>
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include "/usr/include/SDL/SDL_keyboard.h"
    #include "/usr/include/SDL/SDL.h"
    #include <iostream>
    #include <ncurses.h>

    using namespace std;
    void inputoutput(SDL_KeyboardEvent *key, SDLMod mod, char mikakirjain,char teksti,char lopullinen,char luettelo,FILE * tiedosto);


    int main( int argc, char* args[]) {
    SDL_Event event;

    char mikakirjain;
    int nro = 1 ;
    char teksti[256];
    char lopullinen[256];
    char luettelo;
    string kirj;
    string stringi;
    FILE * tiedosto;




    initscr();
    raw();


    if ( SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf( stderr, "\"SDL initializion\" mokasi: %s \n", SDL_GetError() );
    exit( -1);
    }


    if( !SDL_SetVideoMode(320, 200, 0, 0 ) ) {
    fprintf(stderr, "Video moodia ei saatu suoritettua: %s \n", SDL_GetError());
    SDL_Quit();
    exit( -1 );


    }



    SDL_EnableUNICODE( 1 );


    while(nro == 1) {



    while( SDL_PollEvent ( &event ) ) {
    kirj = getch();
    stringi = teksti + kirj;



    if( event.type ) {

    if (SDL_KEYDOWN) {
    inputoutput(&event.key, char mikakirjain,char teksti,char lopullinen,char luettelo,FILE * tiedosto);

    }





    }
    endwin();

    }




    }

    }
    void inputoutput(SDL_KeyboardEvent *key, SDLMod mod,mikakirjain, teksti, lopullinen, luettelo,FILE * tiedosto) {
    if(event.key.keysym.sym) {
    luettelo = "%s", SDL_GetKeyName(key->keysym.sym );
    if(SDLK_LCTRL, SDLK_"%c", luettelo) {

    tiedosto = fopen("%c",mikakirjain,"w+");
    teksti = fread("%c.txt",mikakirjain);
    sprintf(lopullinen,"espeak -v fi \"%s\"", teksti);
    system(lopullinen);
    teksti = "";
    }
    else if(SDLK_LCTRL, SDLK_LALT, SDLK_"%c",luettelo) {

    tiedosto = fopen("%c",mikakirjain,"r");
    fwrite(teksti);
    teksti = "";

    }

    }
    return teksti;
    }
    }

    compiling code gcc -lSDl programsname programsname.cpp
    result:
    70:26: error: expected primary-expression before ‚char‚70:43: error: expected primary-expression before ‚char‚
    70:55: error: expected primary-expression before ‚char‚
    70:71: error: expected primary-expression before ‚char‚
    70:90: error: expected primary-expression before ‚*‚ token
    At global scope:
    error: ‚mikakirjain‚ has not been declared
    error: ‚teksti‚ has not been declared
    89:74: error: ‚lopullinen‚ has not been declared
    89:86: error: ‚luettelo‚ has not been declared
    In function ‚void inputoutput(SDL_KeyboardEvent*, SDLMod, int, int, int, int, FILE*)‚:
    90:4: error: ‚event‚ was not declared in this scope
    91:3: error: ‚luettelo‚ was not declared in this scope
    92:19: error: ‚SDLK_‚ was not declared in this scope
    92:24: error: expected ‚)‚ before string constant
    94:27: error: ‚mikakirjain‚ was not declared in this scope
    95:5: error: ‚teksti‚ was not declared in this scope
    96:13: error: ‚lopullinen‚ was not declared in this scope
    100:40: error: expected ‚)‚ before string constant
    102:27: error: ‚mikakirjain‚ was not declared in this scope
    103:12: error: ‚teksti‚ was not declared in this scope
    109:8: error: ‚teksti‚ was not declared in this scope
    109:8: error: return-statement with a value, in function returning 'void' [-fpermissive]
    At global scope:
    111:1: error: expected declaration before ‚}‚ token

  2. #2
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,664
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: c++ sdl error

    Code:
    if (SDL_KEYDOWN) {
    inputoutput(&event.key, char mikakirjain,char teksti,char lopullinen,char luettelo,FILE * tiedosto);
    
    }
    This is a function call, not a declaration. I think you have accidentally put the datatypes here instead of on the function itself:

    Code:
    void inputoutput(SDL_KeyboardEvent *key, SDLMod mod,mikakirjain, teksti, lopullinen, luettelo,FILE * tiedosto) {
    ...
    The parameters in the function call don't match those declared in the declaration.

    This function is also returning a value when it is declared to return void:

    Code:
    return teksti;
    Please use [code ]...[/code] tags or the '#' button in the posting toolbar for code. It makes it easier to read.
    Last edited by r-senior; April 5th, 2013 at 02:14 AM.
    Please create new threads for new questions.
    Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].

  3. #3
    Join Date
    Oct 2009
    Location
    ReykjavŪk, Õsland
    Beans
    10,422
    Distro
    Lubuntu 14.10 Utopic Unicorn

    Re: c++ sdl error

    Please don't double-post.
    I have deleted the other one.
    About problems due to upgrading
    Bringing old hardware back to life.
    Please visit Quick Links -> Unanswered Posts

  4. #4
    Join Date
    Apr 2013
    Beans
    2

    Re: c++ sdl error

    Sorry, I'm newbie here =P

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •