Bharat Jain
Bharat Jain

Reputation: 177

How to seperate integer values using sscanf in c?

I have a string which captures details stored in data

User 6%, System 18%, IOW 0%, IRQ 0%

What i am doing is

sscanf(data,"User %d,System %d,IOW %d,IRQ %d",&user,&sys,&iow,&irq);

I am getting wrong output . why ? Is is like i am missing something ?

Upvotes: 0

Views: 57

Answers (2)

Phantom
Phantom

Reputation: 875

You have wrong output because you input string is like:
User 6%, System 18%, IOW 0%, IRQ 0%

But you try to scan a string like:
User 6, System 18, IOW 0, IRQ 0

Upvotes: -2

Paul R
Paul R

Reputation: 212979

You left out the % symbols and some spaces - try:

sscanf(data,"User %d%%, System %d%%, IOW %d%%, IRQ %d%%",&user,&sys,&iow,&irq);

Upvotes: 5

Related Questions