command line option: optarg

Hi

I'm learning how to add in programm another option by command line.
For example in the "my_prog" i want to add a " -k " option and then write a number.
I mean:

my_prog -k 50

and the i should use the number 50.
I'm reading about getopt_long and optarg, and what i have done in the code is to add k in the getop_long as:

c = getopt_long (*pargc, argv, "B:T:z:k:gpdht", long_options, &option_index)

and the k option in the switch as:

    case 'k':
      number_i_want = optarg;
      routine_that_use_number_i_want(number_i_want);
      break;

the program run but it doesn't work appropriately. I think the problem is in optarg that should point to a string.
Anyone can help?

Thanks

D.

-----Post Update-----

Sorry I got it.

All i have to do is translate the char to int with the atoi() function.

number_i_want=atoi(optarg)

Now seems like works!

D.