Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read lines from a file based on a criteria on the lines's content?
    text
    copied!<p>I have a file <code>abc.txt</code> with 8000 lines.The file structure would be:</p> <pre><code>121220122563841210000000 999.999 999.999 999.999 121220122563841210000000 999.999 999.999 999.999 121220122563841210000000 999.999 999.999 999.999 121220122563841210000000 999.999 999.999 999.999 121220122563841210000000 999.999 999.999 999.999 121220122563841210000000 0.2563 0.25698 2.3658 121220122563841210000000 999.999 999.999 999.999 121220122563841210000000 999.999 999.999 999.999 121220122563841210000000 2.365 2.365894 0.15463 121220122563841210000000 999.999 999.999 999.999 121220122563841210000000 999.999 999.999 999.999 121220122563841220000000 4.2563 6.25698 25.3658 </code></pre> <p>The sequence goes on.</p> <p>I needed to write a program to read the line which do not contain 999.999.Here's how I went.I made a comparison with the values that I read,but it's giving the complete file as output.What is the correct way to do it?</p> <pre><code>#include &lt;stdio.h&gt; int main() { FILE *fp,&amp;fp2; char aa[50]; float a,b,c; fp=fopen("abc.txt","r"); fp2=fopen("aa.txt","w"); while(!feof(fp)) { fscanf(fp,"%s %f %f %f",&amp;aa,&amp;a,&amp;b,&amp;c); if((a!=999.999)&amp;&amp;(b!=999.999)&amp;&amp;(c!=999.999)) fprintf(fp2,"%s %f %f %f",&amp;aa,&amp;a,&amp;b,&amp;c); } fclose(fp); fclose(fp1); } </code></pre> <p>When I try to use</p> <pre><code>if((a=999.999)&amp;&amp;(b=999.999)&amp;&amp;(c=999.999)) </code></pre> <p>it's giving only lines that contains <code>999.999</code> but I want the lines which do not contain <code>999.999.</code>.Bear with me I am new to C.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload