it doesn't append the line for some reason.
the output is...
C:\Program Files\tester\.txt
as opposed to...
C:\Program Files\tester\filename.txt
whole code just in case...
Code:
#include <stdio.h>
int testmkr();
main()
{
printf("Hello, would you like to make a test or take one.\n\
\npress '1' to make a test\nor '2' to take a test");
if(getch() == '1')
{
system("cls");
printf("Loading test maker...");
testmkr();
}
}
testmkr()
{
char title[200];
FILE *tfile = NULL;
char buf[BUFSIZ];
char *titlefile;
system("cls");
printf("...Loading complete");
system("cls");
puts("\n\nEnter title of test: ");
if (fgets(buf, sizeof(buf), stdin) != NULL)
{
if ((titlefile = strchr(buf, '\n')) != NULL)
*titlefile = '\0';
}
strcpy(title,"C:\\Program Files\\tester\\");
printf("\nfolder: %s",title);
strcat(title,titlefile);
printf("\nfolder with file name: %s",title);
strcat(title,".txt");
printf("\n>%s<", title);
tfile = fopen(title, "w");
if(tfile == NULL)
{
printf("Error: file was not made");
}
else
{
fprintf(tfile,"testing");
}
fclose(tfile);
getch();
}
Im I erasing it or something please help. Thank you