c - how to extract integer from a string and assign each set of strings to different variables? -


i have following string.

str[]="10,2"; 

i want assign '10' to:

int n; 

and '2' to:

int k; 

i tried using index, string copy , many more methods, didn't work.

#include<stdio.h>  int main(void) {     int n,k;     char str[]="10,2";     if(sscanf(str,"%d,%d",&n,&k)==2)//it return 2, if both parameter has been assigned         printf("%d %d\n",n,k);     return 0; } 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -