# Dev- C++

This is a discussion on Dev- C++ within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by tuurb046 Hi again. I have followed your steps and i have a few questions: 1) how to ...

1. Originally Posted by tuurb046
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. 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

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. Originally Posted by tuurb046
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.

4. 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. They are arguments passed to main. They contain the command line arguments passed to your application.

6. Originally Posted by tuurb046
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.

Page 2 of 2 First 12