Thread: Pointer manipulation

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    7

    Pointer manipulation

    Greetings,

    I am writing a program that based around the command line input of a phone number (numbers only).

    I understand that the number will be stored in char *argv[].
    (i.e. argv[1])

    I want check each digit in the phone number. How would I go about doing this?

    for example:
    a simple piece of code that will print each digit to stdout would suffice

    thank you for your time

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    If argv[1] is a string, then argv[1][i] may be a character in the string.
    Code:
    #include <stdio.h>
    
    int main (int argc, char *argv[])
    {
       if ( argc > 1 )
       {
          int i;
          for ( i = 0; argv[1][i]; ++i )
          {
             printf("%c\n", argv[1][i]);
          }
       }
       return 0;
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    7
    sorry.... the PHONE NUMBER is an argument for the program

    i.e.

    programname 4588742

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    7

    thanks

    thank you

    I tried that before but I put
    Code:
    printf(argv[1][i]); // instead of
    
    printf("%c\n",argv[1][i]);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-15-2009, 08:38 AM
  2. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  3. Pointer Manipulation with strcat()
    By radiohead in forum C Programming
    Replies: 3
    Last Post: 03-03-2006, 07:17 AM
  4. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 09:40 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM