Scanf binary data
Reading binary numbers to array from file C. Hi, I have an input file that has X bits per line, with X lines in total. What's the best way to read this data into an array using C? I figure I should add some sample code - this throws a seg fault: Gah, I've gotten it to work partially, but now I've read elsewhere I need to build structures and what not to get it to scale and read properly.
Use chars, freadand open the data with rb e. Sorry, I don't quite understand - you scanf binary data you are reading binary numbers in your title but then refer to "bits" and finally use fscanf to read into an undeclared variable.
Another area the raises confusion is the reference to lines of data in the file - usually but not exclusively binary files are contiguous streams of scanf binary data. I think maybe it would help if you could "re-define" what you are trying to achieve and we will try to assist.
Bouncingwilf Hah, sorry about that. Is there delimiting in the input file, and if so, what is it? There are as many lines as there are bits in a line. So, if I have a line with 0s and 1s, then the file has lines, with 0s and 1s dispersed in a random sequence in each line.
One thing that can scanf binary data a difference to how we approach this: If Scanf binary data understand you correctly, it's the second of these. Yes, it's the latter. I just had another look at post 2 in this thread. I think I scanf binary data a clue.
In C, one way of defining scanf binary data string is scanf binary data an array of characters, something like this, which sets aside an area of 20 bytes for your string: If you want to have an array of strings, you will need to do something like this: Alright, so it stands, a snippet of my semi-working code looks like this: That's why it gets so messed up.
Is there a way for it to skip the line break delimiter? First off, thank you Mr. Lisati for your clarification about 2d arrays and strings! When you get that working to your satisfaction, you may want to try using fgets and dynamically set the size of the arrays at runtime assuming the arrays are always square. It easy from there to determine the number of elements in each dimension of the array and the use malloc to allocate the necessary space.
That way, if you inadvertently open a file of the wrong size, the program shouldn't crash. Bouncingwilf Right, I am using fgets see my previous psotbut it is reading the end of line character for some reason. I don't think it's actually reading the Newline character. There was just something screwing going on with the way I was outputting it. Anywy,y my problem's solved! Square 'char' matrices solved the problem!