How to parse and validate a number in C

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 พ.ย. 2024

ความคิดเห็น • 10

  • @bikrae
    @bikrae 4 ปีที่แล้ว

    YOU ARE A GENIOUS!!! been trying to find out how to validate numbers when a user inputs a no number value, this is simple and works just fine!!!

  • @kauealmeida
    @kauealmeida 3 ปีที่แล้ว

    Bro, thanks for your channel!!! Now I will sucessed on algorithms in college. Keep with your great work

  • @rodolfokey7835
    @rodolfokey7835 3 ปีที่แล้ว

    Greta video; great explanation. Much better than the man pages in UNIX. Cheers mate

  • @Phantom-pj1ls
    @Phantom-pj1ls 4 ปีที่แล้ว +1

    Wow Ive just discovered your channel! You're an amazing teacher!!
    So What about if my str is something like "123Abetc"
    How can I separate the int part from the char part to evaluate them separately?
    Ive read strtol can accomplish this but I haven't figured out how yet!
    Thank you very much!

    • @CodeVault
      @CodeVault  4 ปีที่แล้ว +3

      Yes, you can use strtol to separate the two. Here's a code snippet:
      char str[] = "123ABetc";
      char strPart[100];
      char* endPtr;
      long int numPart = strtol(str, &endPtr, 10); // numPart will be 123
      // Here endPtr will point to the first letter in the str string.
      printf("%s
      ", endPtr); // Would print just the string part from the original string
      strcpy(strPart, endPtr); // strPart will be "ABetc", this will save the remamining string to another location (in strPart) which you can freely modify
      At the end:
      numPart will have the value 123
      strPart will have the value "ABetc"
      And thanks for the support, it is much appreciated!

  • @sherzodernazarov7514
    @sherzodernazarov7514 หลายเดือนก่อน

    thanks

  • @wick6296
    @wick6296 4 ปีที่แล้ว

    Hey ! Thank you for the vids ! Can you show me how to make a header or a file , where I can have commonly used funtions stored , for example , to use them faster when I need them . So , just to include the header , in use whatever function I need .

    • @CodeVault
      @CodeVault  4 ปีที่แล้ว

      Sure thing, I can make a video on that. Expect it next week.

  • @deset1010
    @deset1010 2 ปีที่แล้ว

    Thank you for the video. What about real numbers how to validate 123.45 ?

    • @CodeVault
      @CodeVault  2 ปีที่แล้ว

      Try using strtof or strtod: www.cplusplus.com/reference/cstdlib/strtod/
      Basically the same as strtol but for real numbers