Oaky bear with me cause i am very new to C however i know a bit of java.
I am trying to test out reading parametes from the command line, anyway they read in as character strings initially right? I want to read in a number, lets say 20. So anyway i want to save it as an int so i can manipulate later. i figured with this i would read it in as an array jsut cause the argv is an array too and it would be easier. here is what i worte to try and test it out. I read stuff in and the array comes out as NULL, but when i comment out my attempt at casting it outputs the everything just fine. any info or advice??
CODE::::
#include <stdio.h>
main(int argc, char** argv)
{
int i;
int array[4]; /* my array for storing as ints*/
printf("argc = %d\n", argc);
for (i = 0; i < argc; i++)
array=(int) argv; /* my attempt at casting*/
printf("argv[%d] = \"%s\"\n", i, argv);
}
Thanks in advance!!!!
I am trying to test out reading parametes from the command line, anyway they read in as character strings initially right? I want to read in a number, lets say 20. So anyway i want to save it as an int so i can manipulate later. i figured with this i would read it in as an array jsut cause the argv is an array too and it would be easier. here is what i worte to try and test it out. I read stuff in and the array comes out as NULL, but when i comment out my attempt at casting it outputs the everything just fine. any info or advice??
CODE::::
#include <stdio.h>
main(int argc, char** argv)
{
int i;
int array[4]; /* my array for storing as ints*/
printf("argc = %d\n", argc);
for (i = 0; i < argc; i++)
array=(int) argv; /* my attempt at casting*/
printf("argv[%d] = \"%s\"\n", i, argv);
}
Thanks in advance!!!!