So I've got a text file:
5f6
2f8
2f2
And I'm reading in the values : 5,6,2,8,2,2 where the first two numbers are always rows x columns, then I'm trying to draw rectangles in retrospect to the files values (This works, but after running the program and when it prints them, it seg faults).
#include <stdio.h>
#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char * argv[])
{
initscr();
cbreak();
noecho();
char str[100];
static char * row;
static char * col;
static int i;
static int j;
static int k;
static int x;
static int y;
int count = 0;
FILE* file;
file = fopen(argv[1],"r");
if(file == NULL)
{
mvprintw(0,0,"File returns null pointer");
exit(1);
}
while(!feof(file))
{
fgets(str,100,file);
row = strtok(str,"x");
col = strtok(NULL," \n");
x = atol(row);
y = atol(col);
for(j=0;j<x;j++)
{
for(k=0;k<y;k++)
{
mvprintw(k+5,j+5+count,".");
refresh(); //Space out drawing each rectangle? so they don't overlap
}
}
count+=5;
}
fclose(file);
getch();
endwin();
return (0);
}
I'm not really sure on how to proceed here, how would I go about eliminating this seg fault, and possibly spacing out the resultant drawing (The count variable doesn't seem to do it).