0

I have to take input like this in two different variables.

e.g.

I am an engineering student, 34.

string:- I am an engineering student.
int:- 34

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
Mihawkeye
  • 1
  • 1

1 Answers1

0
#include <stdio.h>
int main()
{
    
    char str[100];
    int age;
    scanf("%[^,],%d",str,&age);
    printf("str=%s\nage=%d",str,age);
    return 0;
}

scanf can set what character to terminate

Gerrie
  • 736
  • 3
  • 18
  • `"%[^,]` lacks a width limt and is worse than [`gets()`](https://stackoverflow.com/q/1694036/2410359). Consider `"%99[^,] ,%d"` and check `scanf()` return value. – chux - Reinstate Monica Nov 01 '20 at 13:27