Creating command line

This is a discussion on Creating command line within the C Programming forums, part of the General Programming Boards category; Hi I'm making an application with a commandline. Not, starting the application with arguments, but a commandline within it. So, ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    6

    Creating command line

    Hi

    I'm making an application with a commandline. Not, starting the application with arguments, but a commandline within it.

    So, i reseived data with scanf() and i've to check it.

    My question: how do i put the command in an array as argv[] ?
    So, that the user sends:
    logon phpnerd 8549256

    and the fucntions puts that in an array:
    argv[0] = "logon";
    argv[1] = "phpnerd";
    argv[2] = "8549256";

    Thnx

    PHPnerd

    (my nick isn't really true )

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Why strcpy is not good?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    copying is not the problem, but exploding it by the ' ' (space) is the problem

    PHPnerd

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    You want to parse the string stopping on whitespaces?
    scanf("%s %s %s", buf1, buf2, buf3);

    //yeah, yeah, I know %s is not safe - but just to show the idea

    %20s is better for buffer long enough

    The second approach - use strchr + strncpy for example
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    aah, ok, then i have to make a scanf() in stead of gets() :P

    (ive to create all functions by myself)

    PHP

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Never use gets.
    Use fgets instead of gets.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    lolz, i can't use scanf() and fgets() because i dont have they

    Who has a scanf() function for me?

    PHPnerd

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,735
    Um, what can you use?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    Wait a moment...

    gets()
    printf()
    vsprintf_help();
    sprintf();
    printf();
    vprintf();
    vsprintf();
    strcmp ();
    strpbrk ();
    strspn();
    strchr ();
    strcpy();
    puts();
    putch();
    memcpy();
    memset();
    memsetw();
    strlen();

    and any other functions, but not for this needed (drivers)

    I can add some new functions if needed

    PHPnerd

  10. #10
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    so use strchr to find a space
    and memcpy to copy a regeon from one space to another
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  11. #11
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    do i need sizeof() for argument 3 of memcpy() ?

    PHP

  12. #12
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by PHPnerd View Post
    do i need sizeof() for argument 3 of memcpy() ?

    PHP
    No, sizeof is of no help here...

    Show your code for father questions
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Creating a rain effect...
    By Raigne in forum Game Programming
    Replies: 11
    Last Post: 12-04-2007, 04:30 PM
  3. Creating Custom Controls
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 12-29-2003, 12:41 PM
  4. problems creating a linked list
    By jamjar in forum C Programming
    Replies: 5
    Last Post: 10-23-2002, 05:50 AM
  5. Creating an Code-template in Visual C++
    By yerrel in forum C++ Programming
    Replies: 1
    Last Post: 06-10-2002, 11:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21