I have the code below to open a file, append some text and then display the contents of that file on the screen. I am new to programming and trying to learn on my own for the company I work for. Any help is greatly appreciated. I was expecting to have this statement - if (fptr == NULL);
be false but when I execute the program I see the message - We are having problems. Any advice? I am also having some trouble understanding how the functions pass paramaters so any links would be helpful on that subject or array of structures which I was told I will need to understand well by the end of the month. Thanks.
-Carl
Code:
#include<stdio.h>
#define MAXLEN 10
main()
{
FILE *fptr;
char myline[MAXLEN];
char filename [] = "data.txt";
fptr = fopen(filename, "a");
if (fptr == NULL);
{
printf("\nWe are having problems\n");
}
fprintf (fptr, "This is working - testing append!\n");
fprintf (fptr, "This is ridiclous!\n");
fptr = fopen(filename, "r");
while (fgets(myline, MAXLEN, fptr) != NULL)
{
printf("%s", myline);
}
fclose (fptr);
return 0;
}