list - toggle through items in a text file using c -
i have list of primes in form
p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 ....
i want write loop select each of these in succession , them (multiply them 1 of primes). not sure how go this; code far looks this
#include<stdio.h> main() { file *fr; fr = fopen ("primes1.txt", "rt"); }
so yeah didn't far. did before amount of data in text file small. file using contains 1 million primes. if can me out thankful!
you should able read numbers individually so:
int n; file *fp; if ( (fp = fopen("foo.txt", "r")) == null ) { // if file's not found return -1; } while ( fscanf(fp, "%d", &n) == 1 ) { // fscanf reads next integer , skip white space, including linefeeds // next value "n" file // can store them in array, manipulate ones read far, etc } fclose( fp );
Comments
Post a Comment