I'm trying to write a function that will read a file into dynamically allocated memory. Here's what I have so far.... the ReadString() Function is what I need help with. It's function prototype is in language.h and it's definition is in language.c . I'm pretty sure I have a mistake with my pointers so if someone could help me i'd appreciate it. This function needs to return arrayPamphlet[] with the contents of the text file, and lengthPtr as an integer with the number of characters in the array. Please don't rewrite out all the code perfectly for me, tell me what i'm doing wrong and how i might be able to fix it so i can actually understand this stuff.
Thanks!
/************************************************** ****************************
* File: proj3.c
*
*
************************************************** ****************************/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "language.h"
int numCharacters;
int numSpaces;
int numPunctuations;
int numDigits;
int numWords;
char filename[20];
char arrayPamphlet[]
char arrayLetters[26]
int lengthPtr;
int main (void)
{
PrintGreeting ();
ReadString(&filename, &lengthPtr);
Analyze ();
PrintResults();
return 0;
}
/************************************************** ****************************
* Function: ReadString
*
* This function reads the entire text file into dynamically allocated memory,
* returns a pointer to the text as it's return value and returns the length
* via the parameter lengthPtr by reference.
*
* Inputs: filename and lengthPtr
* Outputs: lengthPtr, arrayPamphlet
*
************************************************** ***************************/
char *ReadString (char *filename[], int *lengthPtr)
{
printf("\n\n Please enter a file name:");
scanf("%20s",filename[20]);
FILE * pFile;
pFile = fopen (*filename, "r");
return &arrayPamphlet;
}