Question: I have the following code:

```
for (i = 0; i < 13; i++){
    $('.players').append('<div class="rule_dropdown"><select name="rule' + i + '">');
    for(j = 0; j < rules.length; j++){
        $('.players').append('<option>' + rules[j] + '</option>');
    }
    $('.players').append('</select></div>');

}

```

I want to have 13 dropdown lists with the same content. I expect this to happen:

1. First for loop add an opening div and select
2. For each rule in rules array, append an option
3. Add closing select and closing div
4. Go back to #1

But this is what actually happens:

1. First loop add opening AND closing div and select.
2. Second loop add option with the right content

Does anyone know why?

Answer: 
It's not that difficult:

```
#include <stdio.h>

int main() {
  short i, j, y;
  char text[80];

  if (sscanf("123 402 10 aaa bbb cc\nsecond line", "%hd %hd %hd %79[^\n]", &i, &j, &y, text) == 4) {
    printf("success: i=%d, j=%d, y=%d, text=%s\n", i, j, y, text);
  }
  return 0;
}

```

Note that you have to allocate the buffer for the string yourself and make sure that no buffer overflow happens.
You don't need `sscanf`. You can use `strchr` to find the spaces, `atoi` to turn strings into integers, and simple assignment to turn the spaces into terminating zeroes.

You can also do this:

```
#include <stdio.h>
int main(void)
{
 const char *test="123 402 10 aaa bbb cc";
 short i, j, y;
 char c[128];
 sscanf(test, "%hd%hd%hd %[^\n]s", &i, &j, &y, c);
 printf("i=%d j=%d y=%d c='%s'\n", i, j, y, c);
}

```

Yields: `i=123 j=402 y=10 c='aaa bbb cc'`