-
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
-
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;
}
-
sorry.... the PHONE NUMBER is an argument for the program
i.e.
programname 4588742
-
thanks
thank you
I tried that before but I put
Code:
printf(argv[1][i]); // instead of
printf("%c\n",argv[1][i]);