Hello, I'm new to C and I'm not sure what is wrong with my code here.
After I execute, I get this:

Debug assertion failed!
[program address]
File: fgets.c
Line: 60
Expression: str != NULL

It's a really simple program. I'm trying to assign family data from the in file to the out file with formatting (things commented out), but this is just the start of that program but I can't finish it out since I ran into this problem.
I searched the forum first but this same error is either unsolved in C, or in C++. Or the situation is different because the code is more complicated.
Anyway, here's my full code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void main (void)
 FILE *in, *out;
 char people[81];
 int number;
 printf("This program reads in from familyin.txt, formats its data,\n and writes it out to familyout.txt.");
 in = fopen ("c: \\familyin.txt", "r");
 out = fopen ("c:\\familyout.txt", "w");

 fgets (people, 80, in);
 number = atoi(people);
 printf("The text from familyin.txt is \n %s \n", people);
 printf("The numberic value is %i. \n\n", number);
 fprintf(out, "The text from familyin.txt is \n %s \n", people);

 /*familyin = fopen (
 // struct family      {
//				      char name [50];			/* person's name */
//					  char street [50]; 		/* street address */ 
//				      char csz [50];			/* city, state, zip */
//				      char relation [30];		/* relation to you */
////				      char birthday [11];		/* mm-dd-yyyy */
//			         };
 // struct family people[7];

 fclose (in);
 fclose (out);

Edited by CanofCornInfini: n/a

7 Years
Discussion Span
Last Post by Shankye

@Dragon I think he is opening two different files ..

One is familyin.txt and familyout.txt..
Whr you talking about those two???

Votes + Comments
Yes, you are right :)

I run your program, didnt got any error ..

On 16th line while opening file you gave extra space between C: and \\

c: \\familyin.txt"

i just removed that space and program worked fine..

Edited by Shankye: n/a


Thr are some so called Good programming practices in C, Try to follow them to avoid frustration ..

While opening file, use something like this..

if( (file = fopen("FileName.txt",r)) == NULL )
         printf("Error opening file \n Program exiting\n");

If file couldnt be opened in that case NULL is returned by fopen() function,
so by checking whether its NULL or not we will be sure about file operation ..

Happy programming ..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.