1 Replies - 572 Views - Last Post: 02 April 2013 - 10:30 PM Rate Topic: -----

#1 dsmeltaway  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 02-April 13

Why am I getting segmentation fault? Everythin seems fine.

Posted 02 April 2013 - 09:46 PM

So my compiler compiles fine, but when I got to run, it says segmentation fault. what gives? I put cooments on all of the unnecessary parts.

#include <stdio.h>
//#include <stdlib.h>
//#include <time.h>
int open_store(char *point[10][10]);
int main()
{
	char *point[10][10];
	open_store(point);
	return(0);
}

int open_store(char *point[10][10])
{
	int i,j;	
	FILE *grid;

	// srand(time(NULL));
	// int n = rand() % 10;

	//switch(n)
	//{
	//	case 1: 
			grid = fopen("/home/dylan/Desktop/Final Project/grid1.txt","r");
	//		break;
	//	case 2: 
	//		grid = fopen("/home/dylan/Desktop/Final Project/grid2.txt","r");
	//		break;
	//	case 3: 
	//		grid = fopen("/home/dylan/Desktop/Final Project/grid3.txt","r");
	//		break;
	//	case 4: 
	//		grid = fopen("/home/dylan/Desktop/Final Project/grid4.txt","r");
	//		break;
	//	case 5: 
	//		grid = fopen("/home/dylan/Desktop/Final Project/grid5.txt","r");
	//		break;
	//	case 6: 
	//		grid = fopen("/home/dylan/Desktop/Final Project/grid6.txt","r");
	//		break;
	//	case 7: 
	//		grid = fopen("/home/dylan/Desktop/Final Project/grid7.txt","r");
	//		break;
	//	case 8: 
	//		grid = fopen("/home/dylan/Desktop/Final Project/grid8.txt","r");
	//		break;
	//	case 9: 
	//		grid = fopen("/home/dylan/Desktop/Final Project/grid9.txt","r");
	//		break;
	//	default:
	//		grid = fopen("/home/dylan/Desktop/Final Project/grid1.txt","r");
	//}

	for (i = 0;i < 10;i++)
	{
		for (j = 0;j < 10;j++)
		{
			fscanf(grid,"%c",point[j][i]);
		}
		fscanf(grid,"%c\n",point[j][i]);
	}

	for (i = 0;i < 10;i++)
	{
		for (j = 0;j < 10;j++)
		{
			printf("%c",*point[j][i]);
		}
		printf("%c\n",*point[j][i]);
	}
	fclose(grid);

	return(0);
}



Is This A Good Question/Topic? 0
  • +

Replies To: Why am I getting segmentation fault? Everythin seems fine.

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4099
  • View blog
  • Posts: 12,690
  • Joined: 25-December 09

Re: Why am I getting segmentation fault? Everythin seems fine.

Posted 02 April 2013 - 10:30 PM

Please don't open a new topic for an existing problem. Closed.


Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1