Strings in Scanf function
I'm trying to write a program where the user inputs a word, here is an example:
Enter home team : UF
Enter visitor: Miami
Enter game date (mm/dd/yyyy): 09/06/2008
Home Visitor Date
------- ------- -----
UF vs Miami on 09/06/2008
Here is the code I have:
Code:
#include<stdio.h>
int main(void)
{
char h_team, v_team;
int date;
printf("\nEnter home team: ");
scanf("%c", &h_team);
printf("Enter visitor: ");
scanf("%c", &v_team);
printf("\nEnter game date (mm/dd/yyyy): ");
scanf("%d/%d/%d", &date);
printf("\nHome\t \tVisitor\t \tDate");
printf("\n----\t \t-------\t \t----");
printf("\n%c\tvs\t%c\ton\t%d\n", h_team, v_team, date);
return(0);
}
I know that %c only grabs a single character, so how do I grab several characters without having to use arrays...
Thanks