Anonymous
2012-02-14 21:44:17 UTC
#include
#include
#include
#include
#define MAX 81
FILE *openFile(char fileName[]);
int readLine(char str[],FILE *inputFile);
main()
{
char fileName[MAX] = "";
FILE *inputFile = openFile(fileName);
char str[MAX];
readLine(str, inputFile);
return;
}
FILE *openFile(char fileName[]) //Function A
{
FILE *inputFile;
printf("Please enter a filename.\n");
scanf("%s", fileName);
if (!(inputFile = fopen(fileName, "r")))
{
printf("\aCould not open the input file.\n");
exit (100);
} // if
return(inputFile);
}
int readLine(char str[], FILE *inputFile)
{
char str[MAX];
FILE *inputFile;
fgets(str, sizeof (str), inputFile);
printf("Here is your string: \n\t%s", str);
return;
}
-I am trying to get my second function to work, but cannot get it done. SOMEONE PLEASE HELP ME!
Here is what readLine is supposed to do:
Create a function that reads one line into a string (assuming the file is already open), the return should be an int or bool (true if a string was successfully read, false if end-of-file). In addition to the string to read into, you may include the physical size of the string as a parameter. When reading into the string, read to the end of line ('\n') using fgets, then remove the '\n' from the end of the string.
-Thank you for your time!!!