c - Distinguish between numbers and alphabet in a string -
i trying build tcpip communication between server , client in visual studio , client accept string keyboard, , send string server if numbers not alphabet tried below code seems there wrong.
while (rc == socket_error); //try long till there connection (no socket error) printf("conected %s..\n\n", address); { printf("please insert blood pressure values further diagnostic\n "); gets(data); char i; (i = data[0]; <= max; i++) { char n = data[i]; if ((strlen(data) > max) || (strlen(data) == 0)) { printf("argument not allowed!\n\n"); memset(data, '\0', strlen(data)); continue; } if ((n >= 'a' && n <= 'z') ||( n >= 'a' && n <= 'z')) { printf("you have enter number !\n\n"); memset(data, '\0', strlen(data)); continue; //next iteration } }
for (i = data[0]; <= max; i++)
think want initialise 'i' 0 , not data[0] , want traverse data index. that's causing issuewhy want operation in loop? should one-time operation:
if ((strlen(data) > max) || (strlen(data) == 0)) { printf("argument not allowed!\n\n"); memset(data, '\0', strlen(data)); continue; }
the 'continue' in second if again iterate on loop. want 'break' here loop in do-while loop
Comments
Post a Comment