C - stdin to variables -


i want create program can read lines standard input , interpret each line 2 integer numbers separated space. later use shared library work numbers . before start know, best way parse numbers lines. combination of "getline" , storing numbers variables? store numbers until next numbers given.

if want extract integers string,use

sscanf(arr,"%d %d",&num1,&num2); 

where arr array of char containing data want extract 2 integers , num1 , num2 2 int variables.

or else can directly scan 2 ints using

scanf("%d %d",&num1,&num2); 

it better check if scanf (or sscanf) successful. both of these return 2(in case) if successful. check using like:

if(scanf("%d %d",&num1,&num2)==2) //successful else //failed 

or if use sscanf,

if(sscanf(arr,"%d %d",&num1,&num2)==2) //successful else //failed 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -