Thread: How do I write a program that counts but skips certain numbers?

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    150

    How do I write a program that counts but skips certain numbers?

    I need to write a program that counts in Hex to an unsecified number and writes to a file the number it is on when it counts, but I need it to skip 3 and 6.
    I am confused as hell I cannot find such a thing in any of the books I have gotten.
    Could someone help me and also recomend a good C book that is easy enough for an intermediate person to learn(all the books I find are either for beginer or advanced).
    Thank you.

  2. #2
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    initialize a pointer *num to the data that you want to count and write, and use the following two statements to skip 3 and 6....

    if(*num == 3 || *num == 6)
    num++;

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    150
    thank you

  4. #4
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    Quote Originally Posted by juice View Post
    initialize a pointer *num to the data that you want to count and write, and use the following two statements to skip 3 and 6....

    if(*num == 3 || *num == 6)
    num++;
    Say what?!

    @Once-ler

    You'll find book recommendations, a LOT of them, in a sticky in the C Programming forum.

    I'm not sure what you mean by 'counts in Hex'. All values are stored in binary, and are normally converted to decimal for output, but you can also 'convert' or interpret the value as Hex or Octal. Using printf() %o is for octal, and %x is for hex. Any C book would cover this as well as opening and reading from and writing to files.

    To skip 3 and 6 the logical expression would be ( value != 3 && value != 6 ), where value is some variable representing whatever it is you're counting.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 09-02-2011, 04:57 PM
  2. Program skips functions in main
    By En-Motion in forum C++ Programming
    Replies: 5
    Last Post: 02-18-2009, 09:35 PM
  3. Program skips fegts function - HELP
    By Tripod87 in forum C Programming
    Replies: 3
    Last Post: 07-22-2008, 08:26 AM
  4. program skips over code
    By willc0de4food in forum C Programming
    Replies: 9
    Last Post: 11-16-2006, 06:38 PM
  5. my program skips scanf and getchar()
    By jk81 in forum C Programming
    Replies: 15
    Last Post: 11-29-2002, 05:54 PM