More tries at printing...
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. These do change with different inputs as file name and lines of text so it looks like data is being passed to the line[]. I'm thinking maybe a prototype function is the way to go. I tried that out using the line notation but it will not print any of the file. Both methods are in this code... I seriously appreciate your time and help with this!
Code:
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
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;
}
FILE *getOpen()
{
FILE *fname;
char name[13];
printf("Enter a file name: ");
gets(name);
fname=fopen(name, "w");
if (fname == NULL)
{
printf("\nFailed to open the file %s.\n");
exit(1);
}
return (fname);
}
void inOut(FILE *fname)
{
int count;
char line[81];
printf("Please enter five lines of text:\n");
for (count = 0; count < 5; count++)
{
gets(line);
fprintf(fname, "%s\n", line);
}
}
char convert(char *line)
{
int i=0;
while (line[i] != '\0');
{
line[i] = toupper(line[i]);
i++;
}
return 0;
}
char textprint(char *line)
{
int i=0;
while (line[i] != '\0');
{
printf("%s", line[i]);
i++;
}
return (*line);
}
FILE *getOpen()
{
FILE *fname;
char name[13];
printf("Enter a file name: ");
gets(name);
fname=fopen(name, "w");
if (fname == NULL)
{
printf("\nFailed to open the file %s.\n");
exit(1);
}
return (fname);
}
void inOut(FILE *fname)
{
int count;
char line[81];
printf("Please enter five lines of text:\n");
for (count = 0; count < 5; count++)
{
gets(line);
fprintf(fname, "%s\n", line);
}
}
char convert(char *line)
{
int i=0;
while (line[i] != '\0');
{
line[i] = toupper(line[i]);
i++;
}
return 0;
}
char textprint(char *line)
{
int i=0;
while (line[i] != '\0');
{
printf("%s", line[i]);
i++;
}
return (*line);
}