A First C++ App

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

A First C++ App

Post by maboroshi »

C++ is a really tricky language to learn I never realized how involved the language is anyway I wrote this app with help from Gogeta.

Alls it does is accept an NT or Nix command as input and output the results. Pretty simple but ya :-)


Code: Select all

#include <iostream>
#include <stdlib.h>
#include <cstring>



using std::cout;
using std::cin;

int run_sys_call(char *command);

int main()
{

    char *input = new char[1024];
	char buffer[50] = {0};
	int input_length = 0;

    cout << "Enter a unix or dos command: ";

    while(cin.get(buffer, 50))
	{
		if(input_length + strlen(buffer) > 1024)
			break;

		if(strlen(buffer) == 0)
			break;

		memcpy(input+input_length, buffer, strlen(buffer));
		input_length += strlen(buffer);
	}

	run_sys_call(input);

	delete[] input;
    return 0;
}

int run_sys_call(char *command)
{
    system(command);
}

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Re: A First C++ App

Post by Gogeta70 »

Looks good man ^_^
¯\_(ツ)_/¯ It works on my machine...

Post Reply