Originally Posted by
geustuser
I had to include char line[81] as a variable in main() to get it to accept the print feature but instead of the five strings of entered text back, I'm getting three nonsense characters.
That line variable is different than the one you use in inOut. Since it's a local variable, and you don't initialize it or put any useful data in it, it contains garbage, hence your nonsense characters.
I'm thinking maybe a prototype function is the way to go.
I don't know what you mean by this, and I'm not sure you do either. A prototype just tells the compiler about a function (parameters and return type), so it can make sure you use it right. This is only needed if you call the function before you define it (like how you call getOpen in main, but define getOpen after main). The compiler reads from top to bottom and only knows about stuff it's already seen (things above it in the file).
Code:
FILE *getOpen();
void inOut(FILE *);
char convert(char *);
char textprint(char *);
int main()
{
FILE *outFile;
char line[81];
outFile = getOpen();
inOut(outFile);
fclose(outFile);
printf("The File was successuflly written.\n");
char convert(char []);
char textprint(char *line);
fprintf(outFile, "%s\n", line); // print to file
printf("%s\n",line);
getch();
return 0;
}
Those two red lines are prototypes, not function calls. Take them out. Never put a prototype inside a function. The belong where you have the others, above your functions (green text). Also, as I mentioned, the line variable in main is different from the one in inOut. You need to declare one in main, and pass it in to inOut. Note that line is declared as a single array of chars, thus it can only hold one line at a time. If you need to hold several lines, you need an array of array of chars:
Code:
int main()
{
char line[5][81]; // declare line to be an array of 5 "lines", each "line" having room for 80 chars plus the terminating null.
...
inOut(outFile, line); // pass line into inOut
convert(line[0]); // converts the first line to upper case, do this for all lines, using a loop
}
...
void inOut(FILE *fname, char line[][81])
{
int count;
char line[81];
printf("Please enter five lines of text:\n");
for (count = 0; count < 5; count++)
{
fgets(line[count], 81, stdin); // gets is bad, see the FAQ
fprintf(fname, "%s\n", line);
}
}
That should get you going for a bit.