Assigning 2D array coordinates to a struct and retrieve them
I have a 2d array 5x7 (field) and a struct like the following, where T_x and T_y should be the coordinates of the cells owned by a player (that should be maximum 4 per each player)
`struct player{
char name[10];
int T_x[4];
int T_y[4];
};`
I'm assigning to every single cell a random player in this way (ac is an array counter):
for(i=0; i<5; i++){
for (j=0; j<7 ; j++) {
rand_player = rand()%6; // n. player
player[rand_player].T_x[ac] = i;
player[rand_player].T_y[ac] = j;
printf(" %s ", player[rand_player].name);
player[rand_player].T_y[ac]++;
player[rand_player].T_x[ac]++;
}
}
But in this way I'm just printing a name in a given cell.
How can I really assign the cell to a determined random player?
How can I check if a cell field's of the 2d array is already assigned to another player?
PS: the value of the cell's field cannot be changed, I define it in the declaration.
See also questions close to this topic

Getchar() infinite loop
I’m starting to learn from "The C Programing Language" and one of the codes in the book is not working for me. This code suppose to count the number of characters using
getchar()
.Here is my code:
#include <stdio.h> int main() { long nc; nc = 0; while (getchar() != EOF) ++nc; printf("%1d\n", nc); return 0; }
I try to run it and write some characters but when I press
ENTER
, it only starts a new line. It's like it’s never getting out of the loop. 
Failed to optimize a version of QuickSort with one recursive call
I'm trying to implement the QuickSort but with just one recursive call in its code. many Tests are applied to the program. There is a file where it compares it to the real qsort function in order to verify whether the new version of qsort works or not. So it does a lot of tests from 8 integers for the array to 2048 integers.
So when I execute the program, it's supposed to write "OK" at every succesful test like this:
Test with 8 integers OK Test with 16 integers OK Test with 32 integers OK Test with 64 integers OK Test with 128 integers OK Test with 256 integers OK Test with 512 integers OK
The code is shown below
The code to find the median of three
void median(int t[], int n){ int m = ((n  1) / 2); if (t[0] > t[n  1]) { /* t[0] > t[n  1] */ if (t[m] > t[0]); /* t[m] > t[0] > t[n  1] */ else if (t[n  1] > t[m]) /* t[0] > t[n  1] > t[m] */ swap(t[0], t[n1]); else /* t[0] >= t[m] >= t[n  1] */ swap(t[0], t[m]); } else { /* t[0] <= t[n  1] */ if (t[m] < t[0]) ; /* t[m] < t[0] <= t[n  1] */ else if (t[n  1] < t[m]) /* t[0] <= t[n  1] < t[m] */ swap(t[0], t[n1]); else /* t[0] <= t[m] <= t[n + 1] */ swap(t[0], t[m]); } }
The function for partitioning
int partition( int t[], int n) { int l = 0, r = n, tmp; median(t, r); while(1) { do ++l; while(l < n && t[l] < t[0]); // l <= n1 do r; while(t[r] > t[0]); // r >= 0 if( l >= r ) break; tmp = t[l]; t[l] = t[r]; t[r] = tmp; } tmp = t[0]; t[0] = t[r]; t[r] = tmp; return r; }
And the code of QuickSort
void version2(int t[], int size) { int m, l = 0, r = size ; while((r  l) > 1) { m = partition( t + l, r); if( (m  l) < (r  m)){ version2(t + l, m); l = m + 1; } else{ version2(t + m + 1, r); r = m; } } }
When I try to execute it I get only this
Test with 8 integers
As it was in an infinite loop

Getting program to run on command
I'm new here so sorry if this is a dumb/bad question but I just cannot figure out how to do it for the life of me.
So how would one go about linking a c program to a command. For example lets say I had helloworld.c and I entered make helloword and then wanted to run the command helloworld to run helloworld anywhere on the system. How would I go about this (not using bash aliases).

I made a char[] with split and am trying to make it into a String again, but I don't know why this is not working
Why will this code not print out a string?
String s = "My name is Jack"; String[] arr = s.split(""); char[] a = Arrays.toString(arr).toCharArray(); System.out.println(a); System.out.println(new String(a));

Getting an error of incomparable types: Object and int
Here is a code from google foo bar power hungry challenge. I am getting an error. How can I figure out the problem?
Error:
Answer.java:36: error: incomparable types: Object and int if (intList.get(i) == 0  intList.get(i) == 1) { ^ Answer.java:36: error: incomparable types: Object and int if (intList.get(i) == 0  intList.get(i) == 1) { ^ Answer.java:37: error: incomparable types: Object and int if (intList.get(i) == 1){oneExists = true;} ^ Answer.java:49: error: bad operand types for binary operator '<' if (intList.size() == 1 && intList.get(0)< 0){ ^ first type: Object second type: int Answer.java:57: error: incompatible types: Object cannot be converted to Integer for (Integer i : intList) { ^ Answer.java:68: error: incompatible types: Object cannot be converted to Integer for (Integer i : intList) { ^ Note: Answer.java uses unchecked or unsafe operations. Note: Recompile with Xlint:unchecked for details. 6 errors
package foobar.PowerHungry; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; public class Answer { public static String answer(int[] xs) { List intList = new ArrayList(); BigInteger resultNumber = new BigInteger("1");// the result number might be huge which might not fit inside an Integer; //lets convert the int[] to a list of integers so its easier to work with (You don't have to do this, this is just personal preference) for (int x : xs) { intList.add(x); } //if there is only one element just return it. if (intList.size() == 1){ return intList.get(0).toString(); } //Next Lets remove all 0's from the list as anything * 0 = 0 && anything * 1 = itself boolean oneExists = false; for (int i = 0; i<intList.size(); i++) { if (intList.get(i) == 0  intList.get(i) == 1) { if (intList.get(i) == 1){oneExists = true;} intList.remove(i); //we just popped out an element in the so we need to go back as to not skip the moved down element i; } } //if the array is empty check if there was ever a 1 and return the result if (intList.size() == 0){ if (oneExists){return "1";} else {return "0";} } //after removing all the 0's and 1's, if there is one element and its negative, lets return 0 as turning off the panel is better than it draining energy if (intList.size() == 1 && intList.get(0)< 0){ return "0"; } //Lets check how many negative numbers are in the array, if there is an odd number then lets remove the negative number closest to 0 // to create a large subset that comes out to a positive number Integer negativeCount = 0; Integer smallestNegative = Integer.MIN_VALUE; for (Integer i : intList) { if (i<0) { negativeCount++; if (i<smallestNegative) { smallestNegative = i; } } } //Now if the number of negatives is odd remove the smallest negative if (negativeCount % 2 == 1) { intList.remove(smallestNegative); } //now with an even number of negatives and positives, lets multiply all the elements together to get the highest number for (Integer i : intList) { resultNumber = resultNumber.multiply(new BigInteger(i.toString())); } //Return the result as a string return resultNumber.toString(); } }

Checking if a link contains a word in array javascript
How to check if a link contains a word in array?
var substrings = ['connect', 'ready','gmanetwork']; var str = window.location.href if (substrings.some(function(v) { return str === v; })) { alert("true") }