Check if string contains only digits.

Code Snippets 4 U
#include < stdio.h > 
#include < stdlib.h > 
#include < string.h >

  int main() {
    char * str = "5461651 45";
    int digiOnly = 1;
    for (int i = 0; i < strlen(str); i++) {
      if ( * (str + i) < 48 || * (str + i) > 57) {
        digiOnly = 0;
        break;
      }
    }

    if (digiOnly) printf("Yes digits only are present");
    else printf("There are other characters also than digits");

    return 0;
  }

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 53 = fifty four