im trying to make a program that reads a text file in the format:

2
polygon 3
90 90
90 90
90 90
polyline 2
12 80
30 15

(not the real numbers obviously)

and have the program read how many things, what type, how many points for that type, etc and then draw them.

i finally got it to build with no errors, but i keep getting an error that says "debug assertion failed" when i try to debug it.

i can't figure out where i'm going wrong with this
here is my code:

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include "glut.h"


void main(int argc, char **argv)
{
	printf("Blah blah blah \n");
	glutInit(&argc, argv); 
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
	glutInitWindowSize(640, 480); 
	glutInitWindowPosition(100, 150);  
	glutCreateWindow("Assignment 1");
	FILE *in;
	in = fopen("house.txt","r");
	int number;
	int x,y;
	char string[16];
	float r,g,b;
	int polycount;
	
	fscanf(in,"%d\n",&polycount);
	for(int i=1;i<=polycount;++i)
	{
		fscanf(in,"%s%d\n",string,&number);
		if((strcmp(string,"polygon"))==0)
		{
			for(int j=1;j<=number;++j)
			{
				fscanf(in,"%d%d\n",&x,&y);
				glBegin(GL_LINE_LOOP);
				glVertex2i(x,y);
			}
			glEnd();
			glFlush();
		}
		else if((strcmp(string,"polyline"))==0)
		{
			for(int j=1;j<=number;++j)
			{
				fscanf(in,"%d%d\n",&x,&y);
				glBegin(GL_LINE_STRIP);
				glVertex2i(x,y);
			}
			glEnd();
			glFlush();
		}

	}

	printf("press any key to quit");
	getchar();
}

i would greatly appreciate any insight as to what the problem may be. thanks!

i added:

if(in == NULL)
		{
			printf("Error: can't open file.\n");
		}

in and it seems like my file isn't being opened. i can't seem to figure out why. the file is right in the same directory.

> printf("Error: can't open file.\n");
Use
perror("can't open file.");

It'll tell you WHY it can't open the file.

because you are using colon on both side (" ......"); . this parameter only print the value as same plz you no need to close colon like (" ....." ); put your file name after end of colon. then it can be work successfully

it's working now, i had to end up putting the file in my C:// drive and it read it.

This question has already been answered. Start a new discussion instead.