Bifalgorithm post · Computer science one · Conversions

How can you convert a string to a number using sscanf()?

How can you convert a string to a number using sscanf()? (Computer science one · Conversions) — "We’ve previously examined the functions atoi() and atof() that…

Ideas in this flowchart

  • sscanf() convertit une chaîne contenant un nombre en valeur numérique
  • Autres fonctions de conversion examinées précédemment
  • atoi() convertit une chaîne en valeur int
  • atof() convertit une chaîne en valeur double
  • sscanf() est similaire à scanf()
  • scanf() lit son entrée depuis l'entrée standard
  • sscanf() lit son entrée depuis une chaîne
  • Exemple d'utilisation de sscanf()
  • La chaîne s contient « 103212.3214 »
  • La variable x est déclarée comme une valeur double
  • sscanf(s, "%lf", &x) convertit s et stocke le résultat dans x
  • Après l'appel, x contient la valeur 103212.3214
Feed/

How can you convert a string to a number using sscanf()?

No cover

Channel

Computer science one

1 page

"We’ve previously examined the functions atoi() and atof() that allow you to convert strings that hold numeric values to int and double values respectively. Another way to convert strings to numbers is to use a function similar to the familiar scanf() function which reads its string from the standard input. The sscanf() function reads its “input” from a string instead of the standard input.\n\nchar s[] = \"103212.3214\";\n\ndouble x;\n\nsscanf(s, \"%lf\", &x);\n\n//x now has the value"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.