-8

I'm having problems with: (all line 34)

  1. expected unqualified-id before "for"
  2. expected constructor, destructor, or type conversion before '!=' token
  3. expected ,' or;' before "for"
  4. `i' was not declared in this scope

And i can't seem to find a solution, i've looked for sintax errors, but it seems fine to me. Any help appreciated. Thanks!

#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;

int main(int arg[], int length)
{
    char c [3];
    char r [5];
    int i;
    for (i=0; i < 3; i++)
    {
    cout << "Inserisci i numeri delle colonne: (3 numeri) ";
    cin >> c[i];
    }
    for (i=0; i < 5; i++)
    {
    cout << "Inserisci i numeri delle righe: (5 numeri) ";
    cin >> r[i];
    }
    ofstream fout("DatiArray.txt");
    if(fout.is_open())
    {
    cout << "File aperto con successo!\n";
    }
    i=0;
     for(i=0; c[i] !='\0'; i++)
       {
       fout << c[i];
       } 
        cout << "Dati delle colonne scritti nel file DatiArray.txt con successo!\n";
        }

         for ( i=0; r[i] !='\0'; i++)  // this line 
        {
        fout << r[i];
        }
         cout << "Dati delle righe scritti nel file DatiArray.txt con successo!\n";
         }

 system ("PAUSE");    
}
Ankur
  • 3,584
  • 1
  • 24
  • 32

4 Answers4

3

Here:

 for(i=0; c[i] !='\0'; i++)
       {
       fout << c[i];
       } 
        cout << "Dati delle colonne scritti nel file DatiArray.txt con successo!\n";
        }

you have one closing bracket too many.

David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
1

You have an excess } (and, again, later on in your program).

This would have been very easy to spot if you used any sort of rational code indentation scheme.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

Your for loop is outside of your main.

Igor
  • 26,650
  • 27
  • 89
  • 114
0

Apart from what others pointed out, below are my observations.

char c [3];
for (i=0; i < 3; i++)

You are filling up the array till last element. And then,

 for(i=0; c[i] !='\0'; i++)

you are running loop to find null character which you not inserted as there was no space left for that charcter.

ravi
  • 10,994
  • 1
  • 18
  • 36