What's wrong with my problem - Segmentation fault
  
 
Hello everyone, my program is not working and i dont know why! Appear this messenger to me "Segmentation fault". Help me please.
File "matriz.txt":
7 1 6 2 0 0 0 8 4
0 0 8 0 7 0 0 0 0
0 0 4 0 1 0 5 0 7
8 4 0 1 6 0 0 0 2
2 0 0 0 0 0 0 3 5
6 3 0 7 5 0 0 0 0
0 0 2 0 4 7 1 0 0
0 0 3 0 2 8 4 0 9
0 5 0 0 0 1 2 0 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
 
  | 
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <cstdlib>
using namespace std;
void menu();
void lerJogo(char **matriz, char *arquivo, int &verifica);
void imprimeMatriz (char **matriz, int n);
int main ()
{
	char **matriz;	
	int escolhaMenu;
	char *arquivo;
	int verifica = 0;
	arquivo = new char (20);
	
	matriz = new char *[10];
	for (int l = 0; l <= 9; l++)
	{
		matriz[l] = new char[10];
	}
	menu();
	cin >> escolhaMenu;
	while(escolhaMenu != 1 && escolhaMenu != 2)
	{
		menu();
		cin >> escolhaMenu;
	
	}
	cout << "Indique o arquivo texto contendo o jogo: ";
	cin >> arquivo;
		
	lerJogo (matriz, arquivo, verifica);
	imprimeMatriz(matriz, 9);
	
	
			
	
	
	return 0;
}
void menu()
{
	cout << "--------------SUDOKU--------------" << endl;
	cout << "Digite 1 para jogar e 2 para sair:" << endl;
}
void lerJogo(char **matriz, char *arquivo, int &verifica) // ler os dados de entrada da matriz no arquivo
{
	cout << "Antes" << endl;
	ifstream arqEntrada;
	arqEntrada.open ("matriz.txt");	
	cout << "Depois" << endl;
	char numero;
	int l = 1
	int c = 1;  // linha, coluna
	
	
	
	if (!arqEntrada)
	{	
		cout << "Não foi possível encontrar o arquivo: " << arquivo << endl;
		arqEntrada.close();
	}	
	else
	{
		
		while(!arqEntrada.eof())
		{	
			arqEntrada >> numero;
			matriz[l][c] = numero;
			c++;
			if (c == 10)
			{
				c = 1; // volta para a coluna 1
				l++;	// começa a andar a linha
			}
		}
		
		arqEntrada.clear();
		arqEntrada.close();	
	}
}
void imprimeMatriz (char **matriz, int n)
{
	for (int l = 1; l <= 9; l++)
	{
		for (int c = 1; c <= 9; c++)
		{
			cout << matriz[l][c] << " ";
		}
		cout << endl;
	}
}
  |  | 
 
 
 
 
  
 
Your dupe thread in the unix/linux section already has a reply that you should consider.
It may be true that you miss-posted, but you should really put in more effort when you can.
 
 
Topic archived. No new replies allowed.