Help! I Need to read an array of numbers from a txt file with C! | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Help! I Need to read an array of numbers from a txt file with C!

Hi I have an array of numbers with many lines (actually not knowing how many) in a text file. Each line contains 6 numbers. I have to slice/cut in pairs over each line containing the six numbers to apply a function which takes as arguments three vectors with dimension two, then printing the results for each line with the position of each line. I am not sure how to face this problem I can print the whole array but not sure what is the best way to do what I want to do (to pass the data as function's arguments). I am quite new at this language. Should I use fgets?Thanks in advance and sorry for my English!

13th Nov 2021, 1:41 PM
Randomnumber
Randomnumber - avatar
4 Respostas
0
So your text file has example 1 2 3 3 5 6 2 3 4 5 6 7 And you want to make arrays like int number[3]]2] = {1, 2, 3, 4, 5, 6} Which would be like 1 2 3 4 5, 6 So on and so forth?
14th Nov 2021, 12:48 AM
William Owens
William Owens - avatar
0
Mm something like V1[2]={1 2} V2[2]={3 3} V3[2]={3 5} Use v1 v2 y v3 as arguments for my function then print the solutions and then save again the next values in v1 v2 and v3. Compute and print. I need to print for each line the function for each three pairs of numbers.
14th Nov 2021, 1:18 AM
Randomnumber
Randomnumber - avatar
0
Here are some helpful suggestions to opening and reading the text. https://stackoverflow.com/questions/3463426/in-c-how-should-i-read-a-text-file-and-print-all-strings Then parse the string into arrays you need.
14th Nov 2021, 1:42 AM
William Owens
William Owens - avatar
0
Thanks!!! :)
14th Nov 2021, 2:41 AM
Randomnumber
Randomnumber - avatar