У меня проблемы с использованием функций для правильного чтения второго файла моей программы.Вызываемая функция: colAlloc (variables)
.
Мой код ниже:
void readSpaces (FILE * ptrF, char fileN [], double ** m, int * r)
{
ptrF = fopen (fileN, "r");
char s;
int i;
int ctrS = 0;
int c;
int cVal;
for (s = getc (ptrF); s != EOF; s = getc (ptrF))
{
if (s == ' ' || s == '\t' || s == '\t')
{
++ctrS;
}
}
cVal = ctrS / * r;
c = cVal;
colAlloc (ptrF, fileN, m, &r, &cVal);
/**something is not working here so the program is giving a run-time error once it needs to read column**/
fclose (ptrF);
}
//allocate memory for column
void colAlloc (FILE * ptrF, char fileN [], double ** m, int ** r, int ** s) //file pointer, file name, matrix, row, spaces;
{
int i;
int c;
c = & s;
for (i = 0; i < * r; i ++ )
{
m [i] = (double *) calloc (c, sizeof (double));
if (m [i] == NULL)
{
printf ("\nSorry, not enough memory!\n\n");
exit (0);
}
}
printf ("Cols >> %d.\n\n", c);
for (i = 0; i < * r; i ++)
{
free (m [i]);
}
}
Когда я вызываю функцию в функции readSpaces (ptrF, fileN, m, r)
, программа просто падает. Я думаю, что я вызываю функцию неправильно, и путаю использование указателей и вызов по ссылке для соответствующих переменных.
Была бы признательна за помощь.
Спасибо