2 Replies - 591 Views - Last Post: 04 April 2013 - 11:21 AM Rate Topic: -----

#1 dsmeltaway  Icon User is offline

  • New D.I.C Head

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

Declaring, passing arrays with pointers

Posted 02 April 2013 - 08:03 PM

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

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

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

	switch(n)
	{
		case 1: 
			grid = fopen("grid1.txt","r");
			break;
		case 2: 
			grid = fopen("grid2.txt","r");
			break;
		case 3: 
			grid = fopen("grid3.txt","r");
			break;
		case 4: 
			grid = fopen("grid4.txt","r");
			break;
		case 5: 
			grid = fopen("grid5.txt","r");
			break;
		case 6: 
			grid = fopen("grid6.txt","r");
			break;
		case 7: 
			grid = fopen("grid7.txt","r");
			break;
		case 8: 
			grid = fopen("grid8.txt","r");
			break;
		case 9: 
			grid = fopen("grid9.txt","r");
			break;
		default:
			grid = fopen("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]);
	}
	fclose(inp);

	return(0);
}



so this is my code..I am getting a massive headache not being able to pass an array using pointers. where do I use the '*' token and the '&' token?

Is This A Good Question/Topic? 0
  • +

Replies To: Declaring, passing arrays with pointers

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4068
  • View blog
  • Posts: 12,549
  • Joined: 25-December 09

Re: Declaring, passing arrays with pointers

Posted 02 April 2013 - 09:49 PM

First main must be define either as int main(); or int main(int argc, char **argv);.

Second I recommend you study the function tutorials contained in my signature. I doubt that you need the * for your parameters in your function prototype and function implementation. And you probably don't need the ampersand for the function call.


Jim
Was This Post Helpful? 0
  • +
  • -

#3 Joseph_D  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 25
  • Joined: 05-October 12

Re: Declaring, passing arrays with pointers

Posted 04 April 2013 - 11:21 AM

As Jim stated you need to read up on how to use functions properly. Some other problems I noticed after a quick look are:
Line 57 and 59 you are missing &s they will cause a segmentation faults.
Line 61 where did inp come from? you are trying to close a file pointer which has not been opened.
Joseph,
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1