betaros
Computerspezi
Moin,
ich programmiere grade in C++ ein Programm in dem man Profile anlegen kann und stehe noch ziemlich am Anfang
Mein Problem erkennt man wahrscheinlich bei der Ausführung:
Ich kann Fullname nicht angeben Deshalb kommt am Anfang der Ausgabe "�K". Wie kann ich das Problem beheben?
mfg
betaros
ich programmiere grade in C++ ein Programm in dem man Profile anlegen kann und stehe noch ziemlich am Anfang
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;
int menu(int menutype);
int profiles(int profilemenu);
int main(){
int status,menutype = 0;
status = menu(menutype);
if(status == 1){
cout << "Action failed! Maybe wrong Input?" << endl;
return 1;
}
return 0;
}
int menu(int menutype){
switch(menutype){
default: return 1;
case 0:
int input, status;
cout << "Monex 0.01" << endl;
cout << "----------" << endl;
cout << "1) Create Profile" << endl;
cout << "2) Load Profile" << endl;
cout << "3) Delete Profile" << endl;
cin >> input;
status = profiles(input);
if(status == 0){
cout << "Action was successful!" << endl;
return 0;
} else {
cout << "Action failed! Maybe wrong Input?" << endl;
return 1;
}
break;
}
return 1;
}
int profiles(int profilemenu){
switch(profilemenu){
default: return 1;
case 1:
ofstream create_profile("1.txt");
string correct;
do{
char fullname[256], address[256], city[256], country[256];
cout << "Full Name: ";
cin.getline(fullname,256);
cout << "Address: ";
cin.getline(address,256);
cout << "City: ";
cin.getline(city,256);
cout << "Country: ";
cin.getline(country,256);
cout << "Sie heißen " << fullname << " und kommen aus " << address << ", " << city << ", " << country << ". Ist das korrekt? (J/N)";
cin >> correct;
if(correct == "J" || correct == "j"){
char buffer[1028];
strcat(buffer,fullname);
strcat(buffer,":");
strcat(buffer,address);
strcat(buffer,":");
strcat(buffer,city);
strcat(buffer,":");
strcat(buffer,country);
strcat(buffer,"#");
cout << buffer << endl;
create_profile.write(buffer,1028);
create_profile.close();
return 0;
}}while(correct=="N"||correct=="n");
}
return 1;
}
Mein Problem erkennt man wahrscheinlich bei der Ausführung:
Code:
[betaros@Chef ~]$ ./Entwicklung/monex/main
Monex 0.01
----------
1) Create Profile
2) Load Profile
3) Delete Profile
1
Full Name: Address: Zuhause
City: Hier
Country: Am Arsch der Welt
Sie heißen und kommen aus Zuhause, Hier, Am Arsch der Welt. Ist das korrekt? (J/N)j
�K:Zuhause:Hier:Am Arsch der Welt#
Action was successful!
Ich kann Fullname nicht angeben Deshalb kommt am Anfang der Ausgabe "�K". Wie kann ich das Problem beheben?
mfg
betaros