so I'm having the user input a destination, flight time, and a layover time. The input will always look like "destination, 0:00, 0:00" and I'm trying to copy the input and reprint it. I have some function to ensure its inputted in the proper format, but is there a way to print say the flight time after the first comma? Maybe I'm over complicating it, any help would be great! Thanks!
Current Objective: Once I have validated the that the user inputted their string with the correct format, I want to copy it, then reprint. I cannot use sscanf, strtok, or any other function that does tokenization of string data.
#include <stdio.h>
#include <string.h>
/* == FUNCTION PROTOTYPES == */
int checkForComma(char* pUserString, char comma);
int checkForColon(char* pUserString, char colon);
/* == CONSTANTS == */
const char kComma = ',';
const char kColon = ':';
int main()
{
int numbers = 0;
int loopEnd = 0;
int flightTime = 0;
int inputAccepted = 0;
int commaFound = 0;
int colonFound = 0;
while (loopEnd != 1)
{
char programOutput[81] = "";
char userInput[81] = "";
fgets(userInput, 81, stdin);
strcpy_s(programOutput, 81, userInput);
if ((userInput == NULL) || (userInput == '\0'))
{
printf("Please enter valid input!\n");
return 0;
}
if (userInput == '.')
{
loopEnd = 1;
}
while (inputAccepted == 0)
{
commaFound = checkForComma(programOutput, kComma);
colonFound = checkForColon(programOutput, kColon);
if (commaFound && colonFound == 2)
{
printf("Input Accepted!");
while (commaFound && colonFound == 2)
{
int numberCounter = 0;
char* numCheck = programOutput;
}
break;
}
else
{
printf("Input not accepted!");
return 0;
}
}
printf("Press ENTER key to Continue\n");
getchar();
}
return 0;
}
int checkForComma(char* pUserString, char comma)
{
int counter = 0;
char* pCheck = pUserString;
while ((pCheck = strchr(pCheck, comma)) !=NULL)
{
counter++;
pCheck++;
}
return counter;
}
int checkForColon(char* pUserString, char colon)
{
int counter = 0;
char* pCheck = pUserString;
while ((pCheck = strchr(pCheck, colon)) != NULL)
{
counter++;
pCheck++;
}
return counter;
}