Read formatted data from string: how to use sscanf : Console Read String « Console « C / ANSI-C






Read formatted data from string: how to use sscanf


#include <stdio.h>

int main ()
{
  char sentence[] = "This is a line.";
  char str [20];
  int i;

  sscanf (sentence,"%s %*s %d",str,&i);
  
  printf ("%s -> %d\n",str,i);
  
  return 0;
}


           
       








Related examples in the same category

1.Use fgets to read string from standard input
2. Get a string from stdin: how to use gets
3.Get string from console and output it
4.Get string from console and assign it to a char pointer
5.Read string: A simple scanf and printf pair