Segmentation fault

Hi, I try to run this code and i got segmentation fault.
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
#include <iostream>
#include <string.h>
#include <string.h>

using namespace std;

string sf(char** player, string** player_n)
{
	cout<<"hi"<<endl;
	
}

int main()
{
	char* player[8];
	string* player_n[8];
	string* finalwinner[1];

	char p1[6] = {'P', ' ', 'S', ' ', 'R'};
	char p2[6] = {'S', ' ', 'S', ' ', 'P'};
	char p3[6] = {'P', ' ', 'S', ' ', 'R'};
	char p4[6] = {'S', ' ', 'S', ' ', 'P'};
	char p5[6] = {'P', ' ', 'S', ' ', 'R'};
	char p6[6] = {'S', ' ', 'S', ' ', 'P'};
	char p7[6] = {'P', ' ', 'S', ' ', 'R'};
	char p8[6] = {'S', ' ', 'S', ' ', 'P'};

	string in_word[8] = {"ava", "br","as","ds","gt","tr","wq","fd"};
	
	for(int a =0; a<8; a++)
	{
		if(a==0)
		{
			player[a] = p1;
		}
		else if(a==1)
		{
			player[a] = p2;
		}
		else if(a==2)
		{
			player[a] = p3;
		}
		else if(a==3)
		{
			player[a] = p4;
		}
		else if(a==4)
		{
			player[a] = p5;
		}
		else if(a==5)
		{
			player[a] = p6;
		}
		else if(a==6)
		{
			player[a] = p7;
		}
		else if(a==7)
		{
			player[a] = p8;
		}

	}

	for(int b = 0; b<8; b++)
	{
		player_n[b] = &in_word[b];
	}

	sf(player, player_n);

}


the output is as follow:

hi
Segmentation fault (core dumped)


i'm not sure what went wrong with my code.
Last edited on
What do you return from sf?
so as you point out about the return. i modified my codes and it works

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

string sf(char** player, string** player_n, string** finalwinner)
{
	cout<<"hi"<<endl;
	finalwinner = player_n;
	return **finalwinner;
	
}

int main()
{
	char* player[8];
	string* player_n[8];
	string* finalwinner[1];


	char p1[6] = {'P', ' ', 'S', ' ', 'R'};
	char p2[6] = {'S', ' ', 'S', ' ', 'P'};
	char p3[6] = {'P', ' ', 'S', ' ', 'R'};
	char p4[6] = {'S', ' ', 'S', ' ', 'P'};
	char p5[6] = {'P', ' ', 'S', ' ', 'R'};
	char p6[6] = {'S', ' ', 'S', ' ', 'P'};
	char p7[6] = {'P', ' ', 'S', ' ', 'R'};
	char p8[6] = {'S', ' ', 'S', ' ', 'P'};

	string in_word[8] = {"ava", "br","as","ds","gt","tr","wq","fd"};
	
	for(int a =0; a<8; a++)
	{
		if(a==0)
		{
			player[a] = p1;
		}
		else if(a==1)
		{
			player[a] = p2;
		}
		else if(a==2)
		{
			player[a] = p3;
		}
		else if(a==3)
		{
			player[a] = p4;
		}
		else if(a==4)
		{
			player[a] = p5;
		}
		else if(a==5)
		{
			player[a] = p6;
		}
		else if(a==6)
		{
			player[a] = p7;
		}
		else if(a==7)
		{
			player[a] = p8;
		}

	}

	for(int b = 0; b<8; b++)
	{
		player_n[b] = &in_word[b];
	}

	sf(player, player_n, finalwinner);

}


thanks for your help.
Topic archived. No new replies allowed.