Beginning c++ and need help...

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Codiah

Thread Starter
Joined
Sep 27, 2008
Messages
116
So i'm beginning to learn C++ and i need to know how to get my new c++ program to run another program when its executed, and if its possible to get a c++ program to set a variable like the ones used in batch files.. %variablename%

really close to finishing my first project and any help would mean allot...
 

Codiah

Thread Starter
Joined
Sep 27, 2008
Messages
116
I should rephrase all of this so its in context... anyway... heres the code..

#include <stdio.h>
#include <conio.h>
#include <string.h>
char User[21], Pwd[21];
#define UN "adminun"
#define PW "adminpw"
void MkAster();
void PromScr();
int main()


{
int att = 4;

printf("Please enter the following...\n");

for (; att >= 0; att--)


{
PromScr();

if (!stricmp(User, UN) && !strcmp(Pwd, PW))


{
printf("\nUsername and Password accepted!\n\n");
break;
}

else printf("\nInvalid Username or Password\n\nYou have %i attempts more.", att);
}
return 0;
}

void PromScr()


{
printf("\nUsername: "); scanf("%s", &User);
printf("Password: "); MkAster();
}

void MkAster()


{
int i = 0, geth = 0;


do {

geth = getch();
if(geth != 13)


{
if(geth == '\b')


{
if(i!= 0)


{
printf("\b \b");
Pwd = '\0';
i--;
}
}
else if(geth == '13') printf("\b \b");

else

{

Pwd = geth;
printf("*");
i++;
}
}
} while(geth != 13 );

Pwd = '\0';
}


What i want to do is set the password as a system variable when its entered, because i'm using it to verify the programs that follow... and i need to know how to once the password and username are entered, get it to run another program..

if i need to explain anything else just ask..
 
Joined
Sep 14, 2005
Messages
919
A couple of suggestions...

>Dont mix C with C++ (You are doing this alot here);
>conio.h is nonstandard, dont use it;
>Use std::string over char buffers for storing strings. #include <string> (Note there is no *.h)

If you want to set it as a system variable, you should note this is OS dependent. In order to do this you will need to use the system API. Assuming Windows, it will be the Win32 API. I personally have not done it so cannot help you here.

i need to know how to get my new c++ program to run another program when its executed
This is (again) OS dependent. You can try the Win32 APIs ShellExecute() routine:
Code:
#include <windows.h>

//! execute someprogram.exe
ShellExecute (NULL, "open", "someprogram.exe", NULL, NULL, SW_SHOWNORMAL);
Probably the easiest way is running it from the system() routine though as it doesnt use the Win32 API:
Code:
#include <cstdlib>

//! execute someprogram.exe
std::system ("someprogram.exe");
Both are OS dependent. system() is ANSI C++ though.
 

Codiah

Thread Starter
Joined
Sep 27, 2008
Messages
116
Well i certainly appreciate the feedback... but like i said i'm just learning C, so when it comes to terminology and right ways to do things i still come up rather short in most cases... so i guess i'm going to do a little research into this API thing for now... but again..
thanks...
 
Joined
Sep 14, 2005
Messages
919
No worries :) I personally recommend staying clear of the Win32 application programming interface (API) for now until you get further into C++. The Win32 API is very large and complex and trying to learn it without having a good understanding of C can be hard.
 

Codiah

Thread Starter
Joined
Sep 27, 2008
Messages
116
well on another note then, is there anything you could point me towards, i just started with C like two days ago... if maybe this isn't the greatest choice for beginners could you point me towards a programming language that is?
 

Codiah

Thread Starter
Joined
Sep 27, 2008
Messages
116
Well, i'm just gonna start as basic as possible and work my way up.. i picked up a rather large book called, SAMS teach yourself C... hopefully it will get me on the right track... and i replace the conio in that program, changed it to iostream and updated my code, but it being put on the backburner till i learn a little more..
 
Joined
Sep 14, 2005
Messages
919
That sounds like a good idea :)

Are you working with C or C++? They are quite different languages ;)
 

Codiah

Thread Starter
Joined
Sep 27, 2008
Messages
116
I've decided to start with C, figure i can easily expand from there later on if i want....
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top