Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I am new at programming in C. For this assignment, I am supposed to pick a file from command line, open the file, read

Hi,

I am new at programming in C. For this assignment, I am supposed to pick a file from command line, open the file, read each line, calculate which values can be triangles and then display which values can be triangles. I do not know where I made a mistake. So far it prints out nothing and I get a warning saying that: " comparison between pointer and integer while (fscanf (f, "%d", &a) == argv[1])". Needs command line argument process and file operations:

Below is my program:

#include

int main (int argc, char *argv[]) { // declare my three variable to represent the length of the three sides of a triangle int a, b, c; int linecount = 0; //declare FILE to read and write a file from user inpput FILE *f = NULL; if (argc>=2) f = fopen(argv[1], "r"); if (f == NULL) { printf("File doesn't exist "); return 1; } //read content of file //Each line of file should have 3 values separeted by a space while(!feof(f)) { a = fscanf (f, "%d", &a); b = fscanf (f, "%d", &b); c = fscanf (f, "%d", &c); //calculate if values represent a triangle or not while (fscanf (f, "%d", &a) == argv[1]) { fscanf(f, "%d", &b); fscanf(f, "%d", &c); if(((a+b)>c)&&((a+c)>b)&&((b+c)>a)) return 1; else; return 0; } //print out values which passed the test printf("%d ", argv[a], argv[b], argv[c]); } return (0); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions