I am writing a short program in c on a linux platform which takes an argument from the command line. My only problem is retrieving that argument. It is an integer.

Here's what is currently in my code:
int seconds = *argv[0];

Thanks :cheesy:


EDIT: Here is the rest of my code:

#include <sys/time.h>
#include <stdio.h>
int main(int argc, char *argv[]){
struct timeval theTime;
 
int timePassed = 0;
gettimeofday(&theTime, NULL);
int time = theTime.tv_sec;
int seconds = *argv[0];
printf("%d", seconds);
 
while(timePassed!=seconds) 
{
timePassed = theTime.tv_sec - time;
gettimeofday(&theTime, NULL); 
}
}

argv[ 0] is the program name. You can see the contents by using this line

printf( "%s", argv[ 0 ] );

To get the first argument, and convert it to an integer, try this code.

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
    int seconds = atoi( (argv[1]) );
    printf("%d", seconds);
}
commented: Good to see you around, Wolfy --joeprogrammer +8

That worked. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.