12 5 64 27 9I have the right to use the fscanf function to read the initially 3 worths and keep them in 3 variables. But I can"t check out the remainder.I tried making use of the fseek function, but it functions only on binary documents.

You watching: Read int from file c++

Please aid me keep all the values in integer variables.



A simple solution utilizing fscanf:

void read_ints (const char* file_name) FILE* file = fopen (file_name, "r"); int i = 0; fscanf (file, "%d", &i); while (!feof (file)) printf ("%d ", i); fscanf (file, "%d", &i); fcshed (file);


How about this?

fscanf(file,"%d %d %d %d %d %d %d",&line1_1,&line1_2, &line1_3, &line2_1, &line2_2, &line3_1, &line3_2); In this case spaces in fscanf match multiple occurrences of any kind of whiteroom till the following token in discovered.

See more: watch wow wow wubbzy online free



Thanks for contributing a solution to Stack Overflow!

Please be certain to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to various other answers.Making statements based upon opinion; ago them up via referrals or individual experience.

See more: how do you say how do you say in spanish

To learn more, view our tips on writing excellent answers.

Article Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of organization, privacy plan and also cookie plan

Not the answer you're looking for? Browse other questions tagged c file file-io scanf line or ask your own question.

c function to check out character by character from a txt file, make it into int and store it in a connected list
website design / logo design © 2021 Stack Exadjust Inc; user contributions licensed under cc by-sa. rev2021.5.14.39313

Your privacy

By clicking “Accept all cookies”, you agree Stack Exreadjust have the right to keep cookies on your gadget and also discshed indevelopment in accordance via our Cookie Policy.

Categories: Q&A