Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to parse a string into variables with sscanf() in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h> 
  
int main(void)
{
    int age;
    char name[20], profession[20];
    char s[50] = "Dan 33 Programmer";

    sscanf(s, "%s %d %s", name, &age, profession);

    printf("name = %s   age = %d   profession = %s", name, age, profession);
         
    return 0;
}

 
/*
 
run:
 
name = Dan   age = 33   profession = Programmer
 
*/


answered Feb 11, 2015 by avibootz

Related questions

1 answer 175 views
2 answers 212 views
212 views asked Jul 14, 2016 by avibootz
1 answer 111 views
111 views asked Jun 28, 2024 by avibootz
1 answer 120 views
1 answer 90 views
...