A_P
A_P

Reputation: 354

how to advance sscanf C?

I'm given a char* arguments. Which is basically a input stream that consists of "hex-address new_val" and I need to read both values as int*. I'm using sscanf() and reading hex-address just fine, but I can't figure out the way to advance to read new_val.No matter what I tried - I get segfault. Here is what I have so far:

 int set_new_val(Cmd *cp, char *arguments) {

  int* addr;

  int* val;

  sscanf(arguments, "%x",&addr);

  sscanf(arguments+?????, "%x",&val);

  /*see if I read it correct*/

  printf("adr = %x || val = %x\n",(unsigned int)*addr,(unsigned int)*val);

  /*not finished*/

  return 0;
}

Upvotes: 0

Views: 643

Answers (1)

A.S.H
A.S.H

Reputation: 29352

int addr, val; // not int*

sscanf(arguments, "%x %x",&addr, &val);

printf("adr = %x || val = %x\n", addr, val);

Upvotes: 1

Related Questions