Thread: seq function in C

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    seq function in C

    Hello guys, I have been learning C for just under a week now and the first assignment is giving me quite a bit of trouble. We are supposed to write the seq function in linux (seq: sequence of numbers (linux)) in C. My current hurdle is how can I have multiple parameters in my input? that is, how can i have my program read whether there are 1, 2, or 3 integers in the input? the following two programs were given to us to help us btw
    Code:
     #include   int main(int argc, char *argv[])  { 	 int i;  	 printf("argc = %d\n", argc);  	 for (i = 0; i < argc; i++) 		 printf("argv[%d] = %s\n", i, argv[i]); }
    and
    Code:
     #include    int main(int argc, char *argv[])  { 	 int i;  	 i = atoi(argv[1]); 	 	 printf("%d\n", i);  }
    Last edited by reine; 01-16-2012 at 12:33 AM.

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    88
    Since this is for school, and there's a policy against giving answers out, I'll give you a strong hint:

    look up "argc" and "argv".

    They play an important role that will be obvious if you google.
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    24
    Its easy go through the link :

    Chapter 13: Reading the Command Line

  4. #4
    Registered User
    Join Date
    Jan 2012
    Posts
    2
    thanks for the help!

    so i'm using code::blocks, how do i pass arguments to the programme? I see how it's done in command prompt
    Last edited by reine; 01-16-2012 at 07:32 AM.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by reine View Post
    thanks for the help!

    so i'm using code::blocks, how do i pass arguments to the programme? I see how it's done in command prompt
    Passing command line arguments in Windows 7

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 06-09-2009, 02:19 AM
  2. Replies: 2
    Last Post: 02-26-2009, 11:48 PM
  3. Print function: sending a function.. through a function?
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 11-05-2008, 05:03 PM
  4. Replies: 14
    Last Post: 03-02-2008, 01:27 PM
  5. Replies: 9
    Last Post: 01-02-2007, 04:22 PM