Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

XelVair

Frischling

  • »XelVair« ist der Autor dieses Themas

Beiträge: 46

Beruf: Student

  • Private Nachricht senden

1

05.01.2010, 21:57

[GELÖST] Ausführen von SYSTEM() befehlen mit Bedingung

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <time.h>
#include <string>

using namespace std;

string command;

int main()
{
cout << "~CustomConsole v1.0 BETA by Xelvair (R)~\n " << endl;
cout << "Type 'HELP' for a list of all current commands." << endl;
    while (3<5)
    {
        cout << endl;
        cout << "con>";
        getline(cin, command, '\n');
        cout << endl;
            if (command == "help")
                {
                    cout << "Help   Shows the overview \nQuit   Quits the console \nPrint   Prints a string to the console \nTime   Shows the actual time \nDate    Shows the actual date" << endl;
                }
        
            else if (command == "print", command == "Print", command == "PRINT")
                {
                    string printstr;
                    cout << "Enter string to print: ";
                    getline(cin, printstr, '\n');
                    cout << printstr << endl;
                }
            else if (command == "quit", command == "Quit", command == "QUIT")
                {
                return 0;
                }

            else if (command == "time", command == "Time", command == "TIME")
                {
                cout <<__TIME__ << endl;
                }

            else if (command == "date", command == "Date", command == "DATE")
                {
                cout <<__DATE__ << endl;
                }

            else if (command == "tracesite")
                {
                char trace[56] = "tracert ";
                char site[200];
                char tracesite[256];
                cout << "Enter site to trace: ";
                cin >> site[200];
                cout << endl;
                tracesite[256] = trace[56] + site[200];
                system(tracesite[256]);
                }

            else
                {
                cout << "Command couldn't be executed!" << endl;
                }
    }
system ("PAUSE");
return 0;
}


Hi Leute, ich bin schon eine Weile hier angemeldet, hab aber nochnie nen Ton von mir gegeben...bin auch ziemlich neu in C++

Jetz hab ich mir mal gedacht, machste einfach mal ein kleines Proggi welches alle sinvollen Features beinhaltet, darunter hätte ich auch gerne den CMD-Befehl "tracert <website>".

Jetzt weiß ich aber nicht, wie ich in system befehle eigene Values einbaue, oben seht ihr meinen fehlgeschlagenen Versuch^^

Ich bedanke mich schonmal im Voraus für eure Hilfe, euer Xel :)

PS: Bidde kein Fachchinesich, bin wirklich ein noob bis jetz ^^

PS2: Ich bin mir darüber im klaren, dass ich auch ein Switch-Statement hätte benutzen können, würde zu lange dauern zu erklären warum ich nestes IF's verwende ;)

2

05.01.2010, 22:04

sprintf (tracesite, "tracert %s", site);

wobei du deinen Inupt mal überarbetien solltest.
cin >> site[200]; macht wenig sinn.

XelVair

Frischling

  • »XelVair« ist der Autor dieses Themas

Beiträge: 46

Beruf: Student

  • Private Nachricht senden

3

05.01.2010, 22:13

Danke E122, aber was mache ich dann damit? Mir wird der übliche tracert-Text nicht angezeigt.

4

05.01.2010, 22:16

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
                char site[200];
                char tracesite[256];
                cout << "Enter site to trace: ";
                cin.get (site, 200);
                cout << endl;
               
              // Kopiert site in <tracesite>

                sprintf (tracesite, "tracert %s", site);
                system(tracesite);


Achtung, ungetestet ;)

XelVair

Frischling

  • »XelVair« ist der Autor dieses Themas

Beiträge: 46

Beruf: Student

  • Private Nachricht senden

5

05.01.2010, 22:21


(Link)


Cheers und Danke =D

[size=7]Jetz muss ich nurnoch verstehn was das ganze Zeugs da tut^^[/size]

Werbeanzeige