Tarlonniel
Programmer
I'm trying to write a simple program that will read a file with 3 columns of data, test the last column against a given value, and print out the current line if the test is true. This is my input file (Table1b.txt):
-1.84 13.16 TO
-1.99 13.36 RRV
-2.20 14.65 TO
-1.19 14.41 G
-2.44 13.34 G
And this is my program:
#include <stdio.h>
main()
{
FILE *fptr_in,*fptr_out;
int i=0;
char type[4];
float met,vel;
fptr_in = fopen("Table1b.txt","r"
fptr_out = fopen("Table1c.txt","w"
while(i<4)
{
fscanf(fptr_in,"%f %f %s",&met,&vel,&type);
if (type=="RRV"
fprintf(fptr_out,"%f %f %s",met,vel,type);
i++;
}
fclose(fptr_in);
fclose(fptr_out);
}
But for some reason I can never get the if statement to read true. The program loops and prints perfectly otherwise - what am I doing wrong??
-1.84 13.16 TO
-1.99 13.36 RRV
-2.20 14.65 TO
-1.19 14.41 G
-2.44 13.34 G
And this is my program:
#include <stdio.h>
main()
{
FILE *fptr_in,*fptr_out;
int i=0;
char type[4];
float met,vel;
fptr_in = fopen("Table1b.txt","r"
fptr_out = fopen("Table1c.txt","w"
while(i<4)
{
fscanf(fptr_in,"%f %f %s",&met,&vel,&type);
if (type=="RRV"
fprintf(fptr_out,"%f %f %s",met,vel,type);
i++;
}
fclose(fptr_in);
fclose(fptr_out);
}
But for some reason I can never get the if statement to read true. The program loops and prints perfectly otherwise - what am I doing wrong??