Thread: C Programming Help.....Newbie Stuck and Confused!!

  1. #1
    Registered User
    Join Date
    Jul 2011

    C Programming Help.....Newbie Stuck and Confused!!

    Hey Guys,
    I am a business major with a twisted sense of having "fun". I
    decided that I wanted to learn c (not c++) programming for just the
    "fun" it. So, I'm new...and I'm stuck lol. I'm trying to validate a
    credit card number using my code. The first thing that I'm trying to
    do is isolate certain digits from the string of 16 or 15 digit credit
    card numbers entered by the user. I've been able to figure out how to
    do this if I provide the number; but can't figure out how to do it as
    a scanf (so the user can provide the number). I know there is a lot
    more code after i isolate, but I'm fairly confident I can figure that
    part out. I just can't get the isolating digits part. I wrote this out
    to show how I have isolated using my own static to i turn
    this into the user giving me the number?

    #include <stdio.h> 
    int main() 
    char number[16] = "123456789112345"; 
    printf("%c\n", number [10]); 
    what I want to do is replace my static "123456789112345" with
    something the user provides through a scanf; but I need to still be
    able to isolate certain digits.....say for instance multiplying every other digit by 2.

    Any suggestions?
    Thanks in advance!

  2. #2
    Registered User
    Join Date
    Jun 2011
    If you wanted to read it in as a string (which is how you have it hard-coded, as a string constant), you could use this:

        char number[16];
    The format specifier for a string is "%s". The "15" is stuck in between there to limit the input so you don't overrun the space you've alloted in the array. You don't want all 16 indices as inputs, you need to save room at the last one for the string-terminating null character, automatically placed there by the "scanf()" function. Just be careful with "scanf()" - it can do some funny things to the unwary.
    Last edited by Matticus; 07-18-2011 at 09:19 PM.

  3. #3
    Registered User
    Join Date
    May 2011
    Around 8.3 light-minutes from the Sun
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie: Stuck on some Math
    By filicudi in forum C Programming
    Replies: 15
    Last Post: 09-01-2008, 07:47 AM
  2. Confused newbie
    By MWalden in forum C++ Programming
    Replies: 37
    Last Post: 06-26-2007, 09:46 AM
  3. newbie : a little confused ?
    By gemini_shooter in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2006, 08:33 AM
  4. Replies: 29
    Last Post: 07-12-2002, 09:18 AM
  5. Newbie - file i/o - I'm stuck
    By djacko in forum C++ Programming
    Replies: 1
    Last Post: 02-22-2002, 09:56 AM