Thread: Not working in linux...

  1. #1
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121

    Not working in linux...

    I am working on a pretty simple game with a couple of friends and i have a constructor that reads from a file. It works fine in windows but in linux it just freezes up. There are no windows specific routines in the constructor but for some reason it will not work. Can anyone help me figure out what is causing this. Any help would be uber appreciated.

    It is an allegro program. In windows i use devc++ to link the allegro libraries. In linux i am using code::blocks and i have `allegro-config --libs` in the 'other linker' box. That is what i have found to do the trick. `allegro-config --libs` is also how i compile allegro from the command line.

    card.cpp
    Code:
    #include <allegro.h>
    #include "standard_tcg.h"
    #include "card.h"
    #include "buttons.h"
    #include <iostream>
    #include <cstdlib>
    #include <fstream>
    #include <cstring>
    using namespace std;
    
    Card::Card(char id[7])
    {
        char set[4];
        char card[5];
        char fname[255];
    
        // parse the id into a set and card number
        for(int i = 0; i < 7; i++)
        {
            if(i < 3)
            {
                set[i] = id[i];
            }
            else
            {
                card[i-3] = id[i];
            }
        }
        card[4] = '\0';
    
    
        strcpy(fname, "card_data\\set");
        strcat(fname, set);
        strcat(fname, ".tcg");
        strcpy(filename, fname);
    
        ifstream IFP (fname);
    
        char comp_card[4];
        char send_buffer[512];
        char check;
        int  Icheck;
    
        int index = 0;
    
        while(!IFP.eof())
        {
            if(check == '[')
            {
                if(strcmp(card, comp_card) == 0)
                {
                    // parsing starts
                    IFP >> check >> check;
    
                    while(check != '>')
                        IFP >> check;
    
                    index = 0;
                    while(check != '#')
                    {
                        IFP >> check;
                        send_buffer[index] = check;
                        index++;
                    }
                    send_buffer[index-1] = '\0';
                    strcpy(Name, send_buffer);
    
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> skipws;
                    IFP >> Icheck;
                    type1 = Icheck;
    
                    IFP >> noskipws >> check;
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> skipws;
                    IFP >> Icheck;
                    type2 = Icheck;
    
                    IFP >> noskipws >> check;
    
                    while(check != '>')
                        IFP >> check;
    
                    //getting ability number 1
                    index = 0;
                    while(check != '#')
                    {
                        IFP >> check;
    
    					send_buffer[index] = check;
    					index++;
                    }
    				send_buffer[index-1] = '\0';
    				strcpy(ability_1, send_buffer);
                }
            }
            IFP >> check;
        }
    }
    
    int Card::Print_Card(BITMAP *bmp, int x, int y)
    {
        textprintf_ex(bmp, font, x, y+10, WHITE, -1,"%d", type1);
        textprintf_ex(bmp, font, x, y+20, WHITE, -1,"%d", type2);
        textprintf_ex(bmp, font, x, y+30, WHITE, -1,"%s", ability_1);
        textprintf_ex(bmp, font, x, y+100, WHITE, -1,"%s", filename);
        return 0;
    }
    I'm at a loss here...
    -- Will you show me how to c++?

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Linux directory separators are '/' not '\\', which may be a problem.

  3. #3
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    And you sir are right on! Thank you so much, i didnt even think to look at that. Thanks a bunch! cheers!
    -- Will you show me how to c++?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You surely aren't using a backslash in a Linux path?
    Edit: Never mind, I am slow.

  5. #5
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121

    I have yet another problem... throwing a crazy error

    I was coding the rest of "parser" for the program i was working on above and I get this error

    Terminate called after throwing instance of 'std::ios_base::failure'
    what(): basic_ios::clear
    Shutting down allegro due to signal #6

    I am using fedora 10 using code::blocks and the latest allegro (linker `allegro-config --libs`)

    if you think the file being used will help I can post it.

    Here is the code:
    Code:
    #include <allegro.h>
    #include "standard_tcg.h"
    #include "card.h"
    #include "buttons.h"
    #include <iostream>
    #include <cstdlib>
    #include <fstream>
    #include <cstring>
    using namespace std;
    
    Card::Card(char id[7])
    {
        Name[0] = '\0';
    
        char set[4];
        char card[5];
        char fname[255];
    
        // parse the id into a set and card number
        for(int i = 0; i < 3; i++)
        {
            set[i] = id[i];
        }
        set[3] = '\0';
    
        for(int i = 0; i < 4; i++)
        {
            card[i] = id[i+3];
        }
        card[4] = '\0';
    
        strcpy(fname, "card_data//set");
        strcat(fname, set);
        strcat(fname, ".tcg");
        strcpy(filename, fname);
    
        ifstream IFP (fname);
    
        if(IFP == NULL)
            allegro_message("could not open: %s", fname);
    
        char comp_card[5];
        char send_buffer[512];
        char check;
        int  Icheck;
    
        int index = 0;
    
        while(!IFP.eof())
        {
            if(check == '[')
            {
                //get the id
                for(int i = 0; i < 4; i++)
                {
                    IFP >> check;
                    comp_card[i] = check;
                }
                comp_card[4] = '\0';
    
                if(strcmp(card, comp_card) != 0)
                    allegro_message("comp_card: %s\nCard   : %s", comp_card, card);
    
                if(strcmp(card, comp_card) == 0)
                {
                    IFP >> noskipws >> check;
                    // get card name
                    while(check != '#')
                    {
                        IFP >> check;
                        send_buffer[index] = check;
                        index++;
                    }
                    send_buffer[index-1] = '\0';
                    strcpy(Name, send_buffer);
                    index = 0;
    
                    // get HP
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    health = Icheck;
    
                    // get type 1
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    type1 = Icheck;
    
                    // get type 2
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    type2 = Icheck;
    
                    // Get ability type 1
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    ab_type_1 = Icheck;
    
                    // get ability type 2
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    ab_type_2 = Icheck;
    
                    // get ability cost 1
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    ab_cost_1 = Icheck;
    
                    // get ability cost 2
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    ab_cost_2 = Icheck;
    
                    // get ability dmg 1
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    ab_dmg_1 = Icheck;
    
                    // get ability dmg 2
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    ab_dmg_2 = Icheck;
    
                    // get ability desc 1;
                    IFP >> check; // because it will be # right now
                    while(check != '#')
                    {
                        IFP >> check;
                        send_buffer[index] = check;
                        index++;
                    }
                    send_buffer[index-1] = '\0';
                    strcpy(ability_1, send_buffer);
                    index = 0;
    
                    // get ability desc 2
                    while(check != '#')
                    {
                        IFP >> check;
                        send_buffer[index] = check;
                        index++;
                    }
                    send_buffer[index-1] = '\0';
                    strcpy(ability_2, send_buffer);
                    index = 0;
    
                    // get retreat type 1
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    rt_cost_type_1 = Icheck;
    
                    // get retreat type 2
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    rt_cost_type_2 = Icheck;
    
                    // get retreat cost 1
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    rt_cost_1 = Icheck;
    
                    // get retreat cost 2
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    rt_cost_2 = Icheck;
    
                    // get weakness
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    weakness = Icheck;
    
                    // get resistance
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    resistance = Icheck;
    
                    // get resistance strength
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    strength_res = Icheck;
    
                    // get evolve
                    while(check != '>')
                        IFP >> check;
    
                    IFP >> Icheck;
                    evolve = Icheck;
    
                    // move the iterator over one
                    IFP >> check;
    
                    // get evolve name
                    if(evolve == 1)
                    {
                        while(check != '#')
                        {
                            IFP >> check;
                            send_buffer[index] = check;
                            index++;
                        }
                        send_buffer[index-1] = '\0';
                        strcpy(ev_name, send_buffer);
                    }
                    else
                        ev_name[0] = '\0';
                }
            }
            IFP >> check;
        }
        IFP.close();
    }
    
    int Card::Print_Card(BITMAP *bmp, int x, int y)
    {
        if(Name[0] != '\0')
        {
            textprintf_ex(bmp, font, x, y+10, WHITE, -1,"%s", Name);
            textprintf_ex(bmp, font, x, y+20, WHITE, -1,"%d", health);
            textprintf_ex(bmp, font, x, y+30, WHITE, -1,"%d", type1);
            textprintf_ex(bmp, font, x, y+40, WHITE, -1,"%d", type2);
            textprintf_ex(bmp, font, x, y+50, WHITE, -1,"%d", ab_type_1);
            textprintf_ex(bmp, font, x, y+60, WHITE, -1,"%d", ab_type_2);
            textprintf_ex(bmp, font, x, y+70, WHITE, -1,"%d", ab_cost_1);
            textprintf_ex(bmp, font, x, y+80, WHITE, -1,"%d", ab_cost_2);
            textprintf_ex(bmp, font, x, y+90, WHITE, -1,"%d", ab_dmg_1);
            textprintf_ex(bmp, font, x, y+100, WHITE, -1,"%d", ab_dmg_2);
            textprintf_ex(bmp, font, x, y+110, WHITE, -1,"%s", ability_1);
            textprintf_ex(bmp, font, x, y+120, WHITE, -1,"%s", ability_2);
            textprintf_ex(bmp, font, x, y+130, WHITE, -1,"%s", filename);
        }
        else
            textprintf_ex(bmp, font, x, y+10, WHITE, -1, "No info was read");
        return 0;
    }
    -- Will you show me how to c++?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    More wasted replies here - http://cboard.cprogramming.com/showthread.php?t=110899
    DONT CROSS-POST!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    I apologize for cross posting. In response to your reply on the other post I believe the problem lies in this code because the problem started when i added the code inside the if(strcmp(card, comp_card) == 0) statement.
    -- Will you show me how to c++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 01-18-2008, 04:06 AM
  2. Some common Linux Questions???
    By code2d in forum Tech Board
    Replies: 4
    Last Post: 12-28-2006, 02:17 AM
  3. Linux Version reccomendation
    By Pobega in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 10-05-2006, 06:48 PM
  4. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2006, 02:36 PM
  5. linux wont boot
    By GanglyLamb in forum Tech Board
    Replies: 4
    Last Post: 02-13-2003, 04:04 PM