dimanche 1 novembre 2015

What is wrong in the if statement which checks a value from shared memory?

In my code the value of flag is determined by a value in shared memory. when a do a print it says that the value is 1, because it prints '1'. So why does my program not proceed with the code in 'if (flag == "1")'?

char *      shm_addr = (char *) MAP_FAILED;
char *      shm_name = "Print";
int         size = -1;
int         rtnval;
char *      flag;
int         numberToPrint = 0;

size = 32;

while (shm_addr == (char *) MAP_FAILED)
{         
    shm_addr = my_shm_open (shm_name);
}

sscanf (shm_addr, "%s", flag);

printf ("\ndata (@ %#x): '%s'\n", (unsigned int)(intptr_t) shm_addr, flag);

while (numberToPrint != 6)
{
    if (flag == "1")
    {
        numberToPrint += 2;
        printf("%i ", numberToPrint + 2);
        flag = "0";
        sscanf (flag, "%s", shm_addr);
    }                
}

Exposure classes

Soo, I tried to write the code when one class acts with each other class. Here are class warior with "Tim" and class witcher with "Max". The console should speak "Now Max hp.. 50" or "Now Tim's hp.. 50 hp", but console sayed "Now Max hp.. 25" or "Now Tim's hp.. 25 hp".. 75 - 25 = 50; 100-50=50; but sayed 75 - 25 = 25; 100-50=25; Help please :c

import java.util.Random;

public class MAXvsTIMvoidVersion {

public static void main(String[] args) {

    warior Tim = new warior();
    Tim.agility = 100;
    Tim.attack = 25;
    Tim.hp = 100;
    Tim.Wariorlvl2 = true;

    witcher Max = new witcher();
    Max.mana = 150;
    Max.attack = 50;
    Max.hp = 75;
    Max.Witcherlvl1 = true;

    Random a = new Random();
    int b = a.nextInt(2);

            if (b == 0)
            {
                Tim.meleeAttack();
                System.out.print("Now Max's hp.." + Max.hp);
            }

            else if (b == 1)
            {
                Max.magicAttack();
                System.out.print("Now Tim's hp.." + Tim.hp);
            }
    }

}


class people
{
    static int hp;
    static int attack;
}

class witcher extends people
{
    int mana;
    boolean Witcherlvl1;
    boolean Witcherlvl2;
    void magicAttack()
    {
        warior.hp = warior.hp - witcher.attack;
        mana = mana - 20;
    }
}

class warior extends people
{
    int agility;
    boolean Wariorlvl1;
    boolean Wariorlvl2;
    void meleeAttack()
    {
        witcher.hp = witcher.hp - warior.attack;
        agility = agility - 20;
    }
}

How to check whether object is empty in handlebars if statement?

In handlebars i need to check if an object is empty and if it isn't then i need to run a loop to grab the content from the object. Below is my code and a link to codepen. I imagine this is quite simple but nothing seems to work. I would have thought that the handlebars #if statement would see an empty object as undefined or 0 and ultimately the condition would be unfulfilled.

<div class="temp"></div>

<script id="temp" type="x-handlebars-template">
    {{#if tabs}}
    <p>true</p>
    {{/if}}
</script>

var template = Handlebars.compile($("#temp").html());

var tabs = {};

var context = {
    tabs: tabs
}

$('.temp').html(template(context));

http://ift.tt/1MqMZnU

C# IF statement

        for (int k = 0; k < proc.Count; k++){
            for (int i = k + 1; i < proc.Count; i++){
                if (proc[k].arrivalTime >= proc[i].arrivalTime && proc[k].priority >= proc[i].priority && proc[k].brust > proc[i].brust){ 
                    temp = proc[i];
                    proc[i] = proc[k];
                    proc[k] = temp;
                }
            }
        }

Input

Process Arrival Brust Priority P0 0 10 5 P1 1 3 1 P2 1 2 1 P3 5 1 5 P4 5 8 2

I want to sort these processes following these rules 1) If the process arrived alone it'll work no matter what. 2) If 2 processes arrived in the same time, we gonna check the priority if the first one has higher priority(lower number) it'll work first, and if they have the same priority we gonna let the one who has lower Brust work first.

There's problem with last 2 processes where's the problem?

P3    5    1     5
P4    5    8     2

process 4 should work because it has higher priority

How to retrieve data in mysql table column?

In Mysql Table, I've a table name: mental_illness that there's two enum row inside as :

N and P

It means Negative and Positive

and here's my PHP code to retrieve data from that table:

  if ($history->getMentalIllness())
  {
    echo HTML::section(3, _("Mental Illness : "));
    echo HTML::para(nl2br($history->getMentalIllness()));
  }

Here's my question:

How to use if else in that above PHP code like this:

If Mental Illness is P, then show Positive text and If Mental Illness is N then show Negative text

Because this code just show P and N instead of Negative and Positive text.

Thank you

Java IF statements not working properly

There is some problem with my if statements. Error shows this Problem Could you help me figure out what's wrong with it ? The main task is that a motor insurance company has 4 categories of insurance based on the age and gender of the applicant.

this is the code :

String gender, age;
char group;
int genderint, ageint;
gender = JOptionPane.showInputDialog("Please specify your gender(1 for male, 0 for female)");
age = JOptionPane.showInputDialog("Please enter your age");
genderint = Integer.parseInt(gender);
ageint = Integer.parseInt(age);
if (gender = 0 || 1 && age = > 18 && < 26) {
    group = "Category A";
} else if (gender = 0 && age = > 27 && < 60) {
    group = "Category B";
} else if (gender = 1 && age = > 27 && < 60) {
    group = "Category C";
} else if (gender = 0 || 1 && age = > 60) {
    group = "Category D";
} else if (gender = 0 || 1 && age = < 18) {
    JOptionPane.showMessageDialog(null, "Sorry, you're too young");
}
JOptionPane.showMessageDialog(null, "You have been assignet to" + group);
}
}

Creating Sudoku game in java [on hold]

I am making a sudoku game in java . I have just studied loops, if else and arrays in detail and have to use a logic from these topics . Basically i have to make 9*9 matrix or array in which we have to generate numbers and also I have to make a checker to check whether solution is right or wrong. Numbers filled in rows and columns should be unique and also every number in 3*3 matrix in 9*9 matrix should also be unique. Game should be made without recursion or use of any methods as i hasn't studied both.