Thread: Dev- C++

  1. #16
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by tuurb046 View Post
    Hi again.

    I have followed your steps and i have a few questions:

    1) how to i create a shortcut to the path entered on the command line?

    2) is the path entered on the command line the same as creating a shortcut to the exe in the project folder (from windows desktop)?

    Cheers Tuurbo46
    Make your shortcut run "cmd.exe /K c:\path\to\program.exe". The /K causes cmd to stick around after the program terminates.

  2. #17
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    Ok all im real lost now. I have an example which i run on the command line (using dev-c++), and when the program is run, the following is displayed:

    Two arguments shlould be supplied
    C:\Dev-Cpp\projects>

    At this point i think the program should enable me to add two arguments, but it does not it expects you to put exe name in again. Can you guys and girls explain in more detail? I have added the code below so you can have a look.

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main(int argc, char *argv[])
    {
    
        int length, element;
        char letter = 'e';
        char *chrptr;
        if(argc != 3)
        {
                printf("%s: Two arguments shlould be supplied\n", argv[0]);
                return 1;
                
        }
        length=strlen(argv[1]);
        printf("'%s' contains %d characters\n", argv[1], length);
        
        if((strchr(argv[1], letter))!=NULL)
        {
            element = strchr(argv[1], letter) - argv[1];
            element++;
            printf("Letter '%c' is first found at character", letter);
            
            printf(" %d in string '%s'\n", element, argv[1]);
            printf("When searching forwards\n");
         }
         else
            printf("Letter '%c' not found in string '%s'\n", letter, argv[1]);
            
         if((strcmp(argv[1], argv[2]))!=0)
            printf("String '%s' and  '%s' are different\n", argv[1], argv[2]);
         else
            printf("Strings are identical\n");
         return 0;
         
    }

  3. #18
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by tuurb046 View Post
    Ok all im real lost now. I have an example which i run on the command line (using dev-c++), and when the program is run, the following is displayed:

    Two arguments shlould be supplied
    C:\Dev-Cpp\projects>

    At this point i think the program should enable me to add two arguments, but it does not it expects you to put exe name in again.
    Can you guys and girls explain in more detail? I have added the code below so you can have a look.
    Why would it enable you to add two arguments? Your program clearly terminates after that error message is printed.

    If you want your program to read in two arguments when they are not provided, then you should program it to do so.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #19
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    Hi,

    ok i will rewind a bit, im trying to learn c with command line arguments, the above example is just a random piece of code not written by me. To date i cannot understand what is going on, the argv[0] etc is puzzleing me.

    With a conventional part of c you get the following:


    Code:
    printf("please enter a letter");
    scanf("%a", &a);
    printf("%a is the letter you entered", a);

    However with command line argruments, where does argv[0] and argv[1] come from?


    Code:
    if(argc != 3)
        {
                printf("%s: Two arguments shlould be supplied\n", argv[0]);
                return 1;
                
        }

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    They are arguments passed to main. They contain the command line arguments passed to your application.
    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.

  6. #21
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by tuurb046 View Post
    Code:
    printf("please enter a letter");
    scanf("%a", &a);
    printf("%a is the letter you entered", a);
    %a is for floats in scanf and doubles in printf, not characters. Use %c for that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Whats better, C-Free or Dev C++??
    By i_can_do_this in forum Tech Board
    Replies: 10
    Last Post: 07-07-2006, 04:34 AM
  2. New to Dev C++/<windows.h>...
    By Cilius in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2005, 01:05 AM
  3. Glut and Dev C++, Programs not Quitting?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-29-2004, 08:43 PM
  4. DEV C++ Limitations?
    By Kirdra in forum Game Programming
    Replies: 3
    Last Post: 09-09-2002, 09:40 PM
  5. Tutorial about Bloodshed Dev!
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 11-13-2001, 07:42 PM