Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!