Função Retonar String
Pessoal, estou mais uma vez com falha de segmentação. Já olhei este código várias vezes procurando um erro, mas não não achei nada. Segue o código:
#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
#include <cstring>
using namespace std;
/* Keywords Structures
{ "<PORTUGOL KEYWORD", "<C++ KEYWORD>" } */
const char keywordConversions[][48][62] = {
{"algoritmo", "{not_implemented}"},
{"inicio", "int main() {"},
{"fim", "return 0; }"}
};
class Translate {
public:
Translate() {
cout << "---------------------------\n";
cout << "Created by Bruno Alano\n(http://brunoalano.com.br)";
cout << "\n---------------------------\n";
/* <! Removido para Compilação de Teste !>
for (int i = 0; i <= 100; i++) {
cout << "Loading..." << " [" << i << "%]";
printf("\r");
fflush(stdout);
usleep(59000);
} */
}
char *Load() {
string code;
string line;
ifstream loader ("example.txt");
if (loader.is_open()) {
while (loader.good()) {
getline (loader,line);
code.append("\n" + line);
}
loader.close();
} else {
cout << "ERRO AO ABRIR ARQUIVO!";
}
/*
cout << "\n- - - - - - - - - - - - - - - - - - - - - -";
cout << "\nFile Info:\n";
cout << "\tLength: " << code.length();
cout << "\n\tFile Name: " << "example.txt";
cout << "\n- - - - - - - - - - - - - - - - - - - - - -\n"; */
char *output;
strcpy(output, code.c_str());
return (output);
}
};
int main() {
Translate t;
cout << t.Load();
return 0;
}
Problema: Falha de Segmentação
Grato, Bruno Alano.
Discussão (1)
Carregando comentários...