
API in C
237
// convert port string to an int
iPort = atoi(szPort);
}
iInteractiveMode ? printf("Connecting to API: %s:%d\n", szIPaddr, iPort) : 0;
fdSock = apiConnect(szIPaddr, iPort);
iLoginResult = login(fdSock, szUsername, szPassword);
if (!iLoginResult)
{
apiDisconnect(fdSock);
iInteractiveMode ? printf("Invalid username or password.\n") : 0;
exit(1);
}
// initialize first sentence
initializeSentence(&stSentence);
// main loop
while (1)
{
// get input from stdin
iInteractiveMode ? fputs("<<< ", stdout): 0;
iInteractiveMode ? fflush(stdout): 0;
if (fgets(cWordInput, sizeof cWordInput, stdin) != NULL)
{
szNewline = strchr(cWordInput, '\n');
if (szNewline != NULL)
{
*szNewline = '\0';
}
}
// check to see if we want to quit
if (strcmp(cWordInput, "quit") == 0)
{
break;
}
// check for end of sentence (\n)
else if (strcmp(cWordInput, "") == 0)
{
// write sentence to the API
if (stSentence.iLength > 0)
Comentários a estes Manuais