Program failed, syntax error.

Hi guys, can you please help me to find the error? I´m working with the latest version of Geany and I actually don´t know how to find my mistake.

Thank you all for your supporting. The code is:

#include <iostream>
#include <vector>
#include <fstream>
#include <string>

std::vector<buul> bitMsimo(const std::vector<int>& datos, int n, int m){

std::vector<buul> bitM;

for(std::size_t i = 0; i < datos.size(); i++){
if(i %n == 0){
if(datos[i] & (1 << m){
bitM.push_back(true);
}else{
bitM.push_back(false);
}
}
}

return bitM;
}



int main(int argc, char *argv[]){

std::cout << "El programa contiene " << argc << " argumentos."
<< std::endl;

if(argc < 2){
std::cerr << "No se ha especificado el nombre del archivo. FIN."
<< std::endl;
return 1;
}

//Colocamos el datos y .dat al nombre del fichero.

std::string nombreArchivo = argv[1];
std::size_t Inicial = nombreArchivo.find("datos");

if(Inicial == std::string::npos){
std::cerr << "No se ha encontrado 'datos'." << std::endl;
nombreArchivo.insert(0,"datos");
}

std::size_t Final = nombreArchivo.find(".dat");

if(Final == std::string::npos){
std::cerr << "No hay .dat" << std::endl;
int tamFinal = nombreArchivo.length();
nombreArchivo.insert(tamFinal, ".dat");
}

//Abrimos el fichero y volcamos los datos.

std::ifstream fichDatos(argv[1]);

if(fichDatos.fail() ){
std::cerr << "No se ha especificado el nombre. FIN." << std::endl;
return 2;
}

//Almacenamos los datos en el vector.

int datoLeido;
std::vector<int> vDatos;
fichDatos >> datoLeido;

while(fichDatos.good() ){
vDatos.push_back(datoLeido);
fichDatos >> datoLeido;
}

//Valor del bit a considerar.

int m;

if(argc >= 3){
m = std::stoi(argv[2]);
}else{
std::cerr << "No se ha espeficicado el valor del bit a considerar."
<< std::endl;
return 3;
}

//Parámetro n de la función.

int n = 2;

if(argc >= 4){
n = std::stoi(argv[3]);
}else{
std::cout <<"El valor n toma 2." << std::endl;
}

//Llamamos a la función.

std::vector<bool> bitM = bitMsimo(vDatos, m, n);

for(std::size_t i = 0; i < bitM.size(); i++){
if(bitM[i] == true){
std::cout << "V, ";
}else{
std::cout << "F, ";
}
}

std::cout << std::endl;
return 4;
}

Hello HJ3475,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



Your program expects something from the command line, but you have neglected to give an example of a proper command line. Do not expect those reading your post to guess at what to use. It will more often be wrong and more difficult to give you an answer.

Next give some idea of what the program is doing or not doing. If there are any errors from a compile post them in their entirety, not what you think they mean. Error messages can mean more to others than they do to you.

In the mean time I will see what I can figure out.

Hope that helps,

Andy
Hello HJ3475,

A quick look at your code shows spelling mistakes, missing ()s, a closing ) in the function. And many syntax errors.

You write: if (argc > = 4). This should be written as ">=", "<=" and "!=". With the space the compiler treats each operator separately.

C++ is case sensitive, so int TamFinal and tamFinal are considered two different variables.


In the line: vData.push_back(read data); I have not found where "read" and "data" are defined and the error says they are not defined. Also it looks like you are trying to put two separate variables into a vector that can only hold one variable per element. You need to explain what you are trying to do here.

At the end of "main" you "return 4". Is there a reason for this? Returning (0) zero means that the program ended with no problem and any number greater than (0) zero means that there was something wrong with the program. You may have a different reason for returning something other than (0) zero and that is fine.

In the function you wrote:
1
2
3
std::vector<buul> bitMsimo(const std::vector <int> & data, int n, int m)
{
	std::vector<buul> bitM;

Did you mean "bool"?

I will try to clean up your code, but may have more questions later.

Hope that helps,

Andy

Edit:
Last edited on
Hello HJ3475,

While working on the program I realized the program uses a file.

You need to include the file, or a good sample, so that everyone will be working with the same information.

For now I have no idea what to put in the file I have created for testing.

Andy

Edit:

Also what are the variables "m" and "n" used for and what values should the have?
Last edited on
> I actually don´t know how to find my mistake.
start by reading the error message
if you don't understand it, then post it and we'll explain it.
Registered users can post here. Sign in or register to post.