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          }     } 

  1. for (i = data[0]; <= max; i++) think want initialise 'i' 0 , not data[0] , want traverse data index. that's causing issue

  2. why 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; } 
  3. the 'continue' in second if again iterate on loop. want 'break' here loop in do-while loop


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -