Make your shortcut run "cmd.exe /K c:\path\to\program.exe". The /K causes cmd to stick around after the program terminates.
Printable View
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;
}
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;
}
They are arguments passed to main. They contain the command line arguments passed to your application.