Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem in File Handling  (Read 1206 times)

0 Members and 2 Guests are viewing this topic.

Bisheshwor

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Problem in File Handling
« on: August 07, 2017, 07:20:59 am »
I am having a problem in my game which includes file handling for some quiz and entertainment. I am having this problem for more than a week and I seriously need to submit my program to the University this week.
 
/void quesengg()
{
    ifstream file1("database/engineering.txt");
    ifstream file11("database/enggans.txt");
    for (int i=0;getline(file1,line1[i]);i++)
    {
        if (i==line_n)
        {
            getline(file1,line1[curr_line[i]]);
        }
    }
    line_n+=2;
    getline(file11,line22[0]);

}

void quessport()
{
   ifstream file1("database/sports.txt");
    ifstream file11("database/sportsans.txt");
    for (int i=0;getline(file1,line1[i]);i++)
    {
        if (i==line_n)
        {
            getline(file1,line1[curr_line2]);
        }
    }
    line_n22+=3;
    getline(file11,line11[0]);
}

void quesmedical()
{

   ifstream file1("database/medical.txt");
    ifstream file11("database/medicalans.txt");
    for (int i=0;getline(file1,line1[i]);i++)
    {
        if (i==line_n)
        {
            getline(file1,line1[curr_line]);
        }
    }
    line_n+=2;
    getline(file11,line11[0]);

}

void quesgk()
{
    ifstream file1("database/gk.txt");
    ifstream file11("database/gkans.txt");
    for (int i=0;getline(file1,line1[i]);i++)
    {
        if (i==line_n)
        {
            getline(file1,line1[curr_line]);
        }
    }
    line_n+=2;
    getline(file11,line11[0]);
}

void ques(){

switch(Wwindow().QueBck)
{
case 1:
    quesengg();
    break;
case 2:
    quessport();
    break;
case 3:
    quesmedical();
    break;
default:
    quesgk();
}

}
void show(){
    void ques();
RenderWindow window(VideoMode (500,500),"!! Quiz !!");
   while(window.isOpen())
{

    Event event1,event;

    while (window.pollEvent(event1))
    {
        if (event1.type == Event::Closed)
                window.close();
    }
    if (Keyboard::isKeyPressed(Keyboard::Return))
        {
            if(texta.getString()== line11[0])
           {
                window.clear();
                texta.setString("");
                window.close();
           }
        }
    if (event1.type == Event::TextEntered && done == false)
    {
    if (event1.text.unicode < 128 && event1.text.unicode !=0)
        {
        str1 = static_cast<char>(event1.text.unicode);
        texta.setString(str1);
        }
    }
            textq1.setString(line1[curr_line]);
            textq2.setString(line1[curr_line+1]);
            textq3.setString(line1[curr_line+2]);

           // textq2.setString(line1[i+1]);
           // textq3.setString(line1[i+2]);
            window.draw(rect1);
            window.draw(rect2);
            window.draw(textq1);
            window.draw(texta);
            window.draw(textq2);
            window.draw(textq3);
            window.display();


}
curr_line+=3;
}
 
When I run this code , though I am calling the sports or medical or gk question , it only calls the engineering questions every time. What might be the problem?
Hoping to get positive response.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem in File Handling
« Reply #1 on: August 07, 2017, 09:10:24 am »
How is that related to SFML?
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Problem in File Handling
« Reply #2 on: August 07, 2017, 12:16:46 pm »
For non-SFML related questions you should use other sites like Stack Overflow.
Besides, since this is an university project, ask your professor or your assistant for help. They get paid to teach you and help, where as random internet users will do it in their free time. ;)

I guess Wwindow().QueBck just always returns 1.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything