I'm making an appointment calendar program with c. My program adds an new appointment with user inputted command: "A 'description' 'mm' 'dd' 'hh'" Where description is a string with a maximum of 20 characters, mm is months, dd is days and hh is hours. Months, days and hours can be 1 or 2 characters long. I have tried to implement readInput function which splits the input string by spacebar and returns a char array which contains: [description, mm, dd, hh] so I can easily get:
desc = array[1];
month = array[2];
day = array[3];
hour = array[4];
Implementing this function was harder than I thought and I have failed miserably. I don't want pointers, just a basic char array containing strings. How should I implement this? Below is my main function.
int main()
{
struct Calendar c;
c.numOfAppointments = 0;
while (true) {
char str[30];
printf("Command: ");
scanf("%[^\n]%*c", str);
if (str[0] == 'A')
{
char command = readInput(str); /*implement this */
}
else if (str[0] == 'L')
{
printCalendar(c);
}
else if (str[0] == 'Q')
{
printf("Exiting program...");
break;
}
}
}
Say I input: A dentist 4 20 10
the returned array should be: ["dentist","4","20","10"]