seg. fault?!

Hi.
My program appeared to give segmentation fault on my windows, but it doesn't execute at all in my ubuntu. Why?

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
#include <iostream>
using namespace std;
/*******************************
* copyright © 2013 Soheil Hooshdaran
*  The purpose of this program is to multiply the two arrays 'a' and  'b' and store the results 
* into the array 'c'
******************************/
main()
{
	int	n, m, p;	//Used as the dimensions of the arrays
	
	
	cout << "Please enter the number of rows of the first array:" <<  endl;
	cin >> n;
	
	cout << "Please enter the number of columns of the first array:" <<  endl;
	cin >> m;
	
	int**a, **b, **c;
/***********Creating an n*m array**********************/
	*a  = new int[n];
    int  dim;   //used to traverse the rows of the array
    int  i;     //used to traverse the columns of the array
    
    
	for(dim=0;dim<n;++m)
       a[dim] = new int[m];
	
/***********Creating an m*p array**********************/
	
	*b  = new int[m];
	
	for(dim=0;dim<m;++dim)
        b[dim] = new int[p];
	  
/***********Creating an n*p array**********************/
	
	*c  = new int[n];
	
	for(dim=0;dim<n;++dim)
	   c[dim] = new int[p];
/*********reading arrays************/

/********reading array a***********/
	for(dim=0;dim<n;++m)
	{
        cout << "please enter the elements of row " << dim 
            <<" of array 'A' seperated by spaces:" <<  endl;
       for(i=0;i<m;++i)
       cin >> a[dim][i];
    }
/********reading array b***********/

    for(dim=0;dim<n;++dim)
    {
      cout << "please enter the elements of row " << dim 
           <<" of array 'B' seperated by spaces:" <<  endl;
      for(i=0;i<p;++i)
	    cin >> b[dim][i];
   }
   cout << "*****Array A**********"   ;
   for(dim=0;dim<n;dim++)
   {
      for(i=0;i<p;++i)
         cout << a[dim][i];
      if( dim == (n-1) )
         cout << endl;
   }
   cout << "*****Array B**********";
   for(dim=0;dim<n;dim++)
   {
      for(i=0;i<p;++i)
         cout << a[dim][i];
      if( dim == (n-1) )
         cout << endl;
   }
   
   while(1);
   
   return 0;
}


I g++'ed my program and then entered ./a.out, but nothing happened

EDIT: It doesn't execute ./a.out at all.
see:
1
2
3
4
5
soheil@soheil-desktop:/media/2318-8E84/MS_Shirazu/Parallel_algorithms/test_suit$ ./a.out
bash: ./a.out: Permission denied
soheil@soheil-desktop:/media/2318-8E84/MS_Shirazu/Parallel_algorithms/test_suit$ sudo ./a.out
[sudo] password for soheil: 
sudo: ./a.out: command not found


Last edited on
 
	for(dim=0;dim<n;++m)


change to

 
	for(dim=0;dim<n;++dim)


What is "p" ?
it's never initialized
therefore the content maybe random
and also you use them

fix those first
> soheil@soheil-desktop:/media/2318-8E84/MS_Shirazu/Parallel_algorithms/test_suit$ ./a.out
> bash: ./a.out: Permission denied
I suppose that the unit is being mounted as `noexec' so you can't execute any file (¿is it an usb-stick?)
So mount it with the `exec' option, or move a.out


About the runtime error http://www.cplusplus.com/forum/general/112111/
Topic archived. No new replies allowed.