Confused

It says SD_Data:63: error: expected ‘}’ at end of input and i have’nt found out a solution I am new to c++

    #include <SD.h>
 int x = 0;
    File myFile;
    File myData;
   File file;
    void setup()
    
      {Serial.begin(9600);
      {Serial.print("Initializing SD card...");
     
      if (!SD.begin(4)); {
        Serial.println("initialization failed!");
        return;
      }
      {Serial.println("initialization done.");
     
      if (SD.exists("num.txt")) {
      }
      else
      {
      myFile = SD.open("num.txt", FILE_WRITE); //TENTAR WRITE AND READ
      if (myFile) {
        Serial.print("Writing...");
        myFile.println("0");
        myFile.close();
        Serial.println("Done.");
      } else {
       
       int num = 0;
        if (myFile.available()) {
          num = myFile.parseInt();
          Serial.println(num);
          
        num++;
       int num2 = num;
        // close the file
        myFile.close();
      } else {
         // if the file didn't open, print an error:
        Serial.println("error opening test.txt");
      
     
      if (SD.exists("num.txt")) {
      SD.remove("num.txt");
      myFile = SD.open("num.txt",FILE_WRITE);
       if (myFile) {
        Serial.print("Writing...");
       // close the file:
        myFile.close();
        Serial.println("Done.");
      } 
      else 
      {
        Serial.println("Error opening num.txt");
      
      
      
      }

       void loop();
  {
++x;
  }

You need to get into the habit of correctly formatting your code. This will make reading and finding bugs much easier. In the Arduino IDE, you can press ctr+t to auto-format your code.

As for your specific problem, try this change:

change

{Serial.print("Initializing SD card...");

to

Serial.print("Initializing SD card...");

i.e. get rid of the { before "Serial.print("Initializing SD card...");"

Does that fix it?

No it doesn't

Power_Broker:
You need to get into the habit of correctly formatting your code. This will make reading and finding bugs much easier. In the Arduino IDE, you can press ctr+t to auto-format your code.

As for your specific problem, try this change:

change

{Serial.print("Initializing SD card...");

to

Serial.print("Initializing SD card...");





i.e. get rid of the { before "Serial.print("Initializing SD card...");"

Does that fix it?

Does this look at all like any loop() that you have seen?

       void loop();
  {
++x;
  }

Ok. Go through your code and match up the { and }. The easiest way is to indent everything inside a set relative to what's outside. Go look at some of the examples and how they format. Keep every { and } on its own line by itself. That will help you match them up. Then maybe you can find the one that's missing.

aarg:
Does this look at all like any loop() that you have seen?

       void loop();

{
++x;
 }

I am trying to make an increment for timestamps

Gkrier:
I am trying to make an increment for timestamps

At the moment your loop contains no code. Take my hint and go look at some loop() functions. Look closely.

aarg:
At the moment your loop contains no code. Take my hint and go look at some loop() functions. Look closely.

I am still working on it I also want to know how I can implement the sum of the incrment into a txt file

Gkrier:
I am still working on it I also want to know how I can implement the sum of the incrment into a txt file

Why? What are you trying to do?

We are sending a rocket up with instruments to record the results i would like to know when the data was tooken

aarg:
Why? What are you trying to do?

Gkrier:
We are sending a rocket up with instruments to record the results i would like to know when the data was tooken

Use an RTC module (real time clock).

This is going to be another problem:

if (!SD.begin(4));

The semicolon ends the if statement and should be deleted.

Go to the internets and google "C++ tutorial". The first few chapters of any C++ tutorial will familiarize you with C++ syntax - what braces and semicolons are for, what a function is, what the scope of variable declarations is. Some of the stuff in the tutorial won't be relevant to Arduino programming, but your problems are very ground-level and basic: you cant code C++ at all. Go do a tutorial.

(deleted)