+ 2
How to iterate over file contents and then store this information in an array ?
I can go as far as making a FILE pointer. reading the file with fgets etc. The next part is my problem, If i want to strip the first 28 chars and the middle 40 chars then how many arrays do i need ? FILE = 2109 Lines firstStrip = 2109 times x 28 chars middleStrip = 2109 time x 40 chars etc. Can i store 28 chars in firstStrip [0]......firstStrip [2109] ? or should i be going 2 dimensional firstStrip [2109 ][28] ? I would only like to keep what i clip and dispose of everything else
8 odpowiedzi
+ 4
I wouldn't use fgets, unless you are guarenteed that the line will not exceed the string. That function will overwrite memory for all of the characters of the line ignoring the size of the string.
Using a two dimensional array is identical to a one dimensional array so use what is easiest for you to understand. The only difference is the expression: firstStrip[line*28+character] vs. firstStrip[line][character].
Using:
char firstStrip[2109*28];
you can put the first 28 characters in firstStrip[0] to firstStrip[27] and the second in firstStrip[28] to firstStrip[55].
+ 3
using arrays is much harder in C than any other languages I've dabbled in.
I over came my problem by just stripping the ip from each line and writing to a file.
i guess my overall issue was accessing the arrays in a different function and the data not being present.
I need to study Arrays and pointers more .
Thank for your answer John Wells
+ 2
John Wells should be able to help with this....
+ 2
Feel free to message me, if you are having issues.You can even tag me in a private code comment.
+ 1
Thank you John Wells , i will work on getting my code into the app for you to see , I think from then you can understand my current mindset and then help me understand better😂
+ 1
thanks John Wells
+ 1
Thank you for the referral *Asterisk*
0
welcome Ed Hanlon