Author Topic: I can not find the error.  (Read 4269 times)

Meta

  • Guest
I can not find the error.
« on: March 26, 2017, 04:50:32 pm »
Hi:

I want to compile the program made in Code :: Blocks and I get this error.
Quote
||=== Build: Debug in Arduino_Led (compiler: GNU GCC Compiler) ===|
C:\Users\Meta\Documents\Code Blocks\Arduino_Led\Arduino_Led\main.cpp|13|error: '::main' must return 'int'|
C:\Users\Meta\Documents\Code Blocks\Arduino_Led\Arduino_Led\main.cpp||In function 'int main()':|
C:\Users\Meta\Documents\Code Blocks\Arduino_Led\Arduino_Led\main.cpp|19|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
||=== Build failed: 4 error(s), 5 warning(s) (9 minute(s), 21 second(s)) ===|

Su código de C++ es:
Code
// Para crear conexión con los puertos COM1 - COM9.
// Serial* Arduino = new Serial("COM7");

// Para crear conexión con los puertos COM10 en adelante.
// Serial* Arduino = new Serial("\\\\.\\COM10");

#include <iostream>
#include <fstream>
#include <Windows.h>
#include "SerialClass.h"
using namespace std;

void main()
{
// Título de la ventana
SetConsoleTitle("Control Led Arduino.");

// Puerto serie.
Serial* Puerto = new Serial("COM4");

// Comandos para Arduino.
char Luz_ON[] = "Luz_ON"; // Envía "Luz_ON" al puerto serie.
char Luz_OFF[] = "Luz_OFF";
char lectura[50] = "\0"; // Guardan datos de entrada del puerto.

int opc; // Guarda un 1 o 2 tipo entero queintroduces desde la consola.

while (Puerto->IsConnected())
{
cout << endl; // Dejamos un retorno.
cout << "Introduzca la opcion deseada: " << endl << endl; // Muestra texto en pantalla.

cin >> opc; // Aquí introduces un número, el 1 o el 2.

switch (opc) // Espera recibir un 1 o un 2.
{
case 1:
// Encener luz.
cout << "Enviando: " << Luz_ON << endl; // Muestra en pantalla textos.
Puerto->WriteData(Luz_ON, sizeof(Luz_ON) - 1); // Envía al puerto el texto "Luz_ON".
break;

case 2:
// Apagar luz.
cout << "Enviando: " << Luz_OFF << endl;
Puerto->WriteData(Luz_OFF, sizeof(Luz_OFF) - 1);
break;

default: // Si haz pulsado otro número distinto del 1 y 2, muestra
cout << "Puse del 1 al 2."; // este mensaje.
}


Sleep(250);
int n = Puerto->ReadData(lectura, 49);
if (n > 0)
{
lectura[n + 1] = '\0';
cout << "Recibido: " << lectura << endl;
cout << "-------------------" << endl;
}

cin.ignore(256, '\n'); // Limpiar buffer del teclado.
}
}

;)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: I can not find the error.
« Reply #1 on: March 26, 2017, 07:01:04 pm »
Quote
Su código de C++ es:
sorry, but this is a english only forum...

second: This is a forum about codeblocks and not about c or general programing questions, so this question violates the rules and probably will get locked

Some hint from my side:
Code
C:\Users\Meta\Documents\Code Blocks\Arduino_Led\Arduino_Led\main.cpp|13|error: '::main' must return 'int'|
and now look at this
Code
void main()

95% of the errors can be fixed if you read the error message carefully....

Offline Aaron

  • Multiple posting newcomer
  • *
  • Posts: 59
Re: I can not find the error.
« Reply #2 on: April 12, 2017, 09:30:17 pm »
Looks like C coding issues, not Codeblocks fault.
« Last Edit: April 12, 2017, 09:33:50 pm by Aaron »