In C, suppose I need to take input from a string
int num,cost;
char *name[10];
printf("Enter your inputs [quantity item_of_name at cost]");
scanf("%d%*c%s%*c%*s%*c%d",&num,name[0],&cost);
printf("quantity of item: %d",num);
printf("the cost of item is: %d",cost);
printf("the name of item is: %d",name[0]);
INPUT
1 book at 12
OUTPUT
Quantity of item is: 1
The cost of item is: 12
The name of item is: book
Now I want to do the same thing in C++. And I have no idea how to approach. gets() returns the whole string.Is there any specific function that I am missing out on? Please help.
scanf. And even if it were initialized: users can easily crash the program with a long enough name. In C, you never use"%s"in ascanfwithout specifying the maximum length.