This program isn't completed entirely but I am taking it one step at a time. Right now I am trying to have the program open a file, detect the terminal size (row and columns), and display a message if a file is entered.
I have set fp to read mode, I have an error message if no file is specified, I have set up my if statements, if column size is less than 80, display an error and if row size is less than 20 display an error... I think this is where my issue is arising, I never actually played around with terminal sizing until this project.
So my question is: how can I get the program to display an error if sizing criteria isn't met?
Note: Like I said I know the code isn't 100% as of now I am just trying to do some debugging on the way so I can eventually get a bigger working project.
Anyways, here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
int main(int argc, char **argv)
{
struct winsize terminal;
FILE *fp;
int c;
ioctl (0, TIOCGWINSZ, &terminal, argv[2]);
fp = fopen(argv[1], "r"); //set open for argv[1] and set it to read mode
column = terminal.ws_col;
row = terminal.ws_row;
if (fp == NULL)
{
fprintf(stderr, "Error opening '%s'.\n", argv[1]); //if not file is specified then close program and give an error
exit(1);
}
c = fgetc(fp); //set c to fgetc
if column < 80 || row < 20) //if temrinal window is less than 80x20, display an error and exit
{
printf("Terminal window must be atleast 80x20!\n"); //display error and close program if column criteria isn't met
exit(1);
}
while(!feof(fp)) //if file is entered, display a test message (this is where later on I will show hex value)
{
printf("Good Job! You picked a file to manipulate!!\n");
exit(1);
}
fclose(fp); //close fp
return 0;
}