Thread: Question about a programming technique to find if certain digits are inside a int

  1. #1
    Registered User
    Join Date
    Feb 2018
    Location
    San Diego, CA
    Posts
    112

    Question about a programming technique to find if certain digits are inside a int

    Hey all, for example let's say I have

    Code:
    sscanf(line, "%s" %d"", string, &date_id);
    


    I am still learning, not that familiar with all the functions but I am coding more, what would be the best function to use (i am using the tutorialspoint web site for tutorials) to for example see if the first digits of an 11 digit int would be "01_", "02_", "03_", meaning 01 for January, 02 for February, 03 for March, and remaining 8 digits are MMDDYYYY. I have

    Code:
    #define DIGITS 11
    this set too. I was wondering, would the modulus operator be a good choice to use in deciding what the first two digits are being inputted. I would like to use a loop that would just break out of the first digits 01_ => 12_ aren't entered. Thanks.

  2. #2
    Registered User
    Join Date
    Feb 2018
    Location
    San Diego, CA
    Posts
    112
    I did a quick search on fscanf() since these 01_, 02_ & 03_ etc are in a txt file I was thinking I can just use "01" for month, without the complicated underscore then the remaining 8 digits (for example 01_01142020 for meeting 1, jan 14 2020)

    Comment's appreciated.

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    717
    Why are the data strings, "01_01142020"? Isn't that "MM_MMDDYYYY"? Seems like redundant redundancy!

    Why do you need the leading "MM_"? Why not just use the final 8 digits, "MMDDYYYY"? It is very easy to extract the Month number form the string.

    Code:
    #define DIGITS 11
    // should be 
    #define DIGITS 12 // or more!  You need to allow room for the trailing Nul byte!
    Can you give us the link for this problem on the Tutorialpoint site?
    Last edited by rstanley; 01-18-2020 at 08:51 AM.

  4. #4
    Registered User
    Join Date
    Feb 2018
    Location
    San Diego, CA
    Posts
    112
    rstanley, I've moved on.

    I'm using int's for MEETING_NUMBER, month, day & year. Yes the underscore was redundant.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Forum Programming Technique
    By veera in forum C# Programming
    Replies: 4
    Last Post: 12-18-2014, 11:00 AM
  2. C programming-How to find same digits
    By Hmmas in forum C Programming
    Replies: 5
    Last Post: 11-18-2014, 07:10 AM
  3. Recursion to find sum of digits of n digit number ?
    By justine in forum C Programming
    Replies: 7
    Last Post: 11-26-2012, 05:35 AM
  4. My Programming Technique
    By User-_-Name in forum C++ Programming
    Replies: 1
    Last Post: 01-15-2011, 11:10 PM
  5. find the digits
    By nimitzhunter in forum C++ Programming
    Replies: 4
    Last Post: 01-05-2011, 02:50 PM

Tags for this Thread