Take a whole number from a char string in c

0

How can I get the number of a string of 9 chars

char * str = "EJ:12345\n";

I tried sscanf (str,"EJ:%d\n",&n) but n seems to be worth 0

    
asked by Luis 28.10.2018 в 00:05
source

1 answer

0

I just tried this code and it works perfect:

  char *str = "EJ:12345\n";
  int n;
  sscanf (str,"EJ:%d\n",&n);
  printf ("%d\n",n);

Check if you are not using the variable "n" for something else. Greetings.

    
answered by 28.10.2018 в 21:18