473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Writing an array to a file

The data is created via a function generator, which is connected to a Data Acquisition Board (DAQ Board). 4000 data points were collected, and an array called ADData was generated to hold the data values. I am trying to save ADData, which is the array holding the 16-bit data values.

I have been using different strategies to save (human readable) data into a text file, file the output is always:

System.UInt16[]

Any ideas on how to save my data?
Nov 13 '07 #1
4 1077
epots9
1,351 Expert 1GB
I'm going to move this to the .NET Forums where the resident experts can better assist you.

**Moved from Programming Challenges
Nov 13 '07 #2
r035198x
13,262 8TB
The data is created via a function generator, which is connected to a Data Acquisition Board (DAQ Board). 4000 data points were collected, and an array called ADData was generated to hold the data values. I am trying to save ADData, which is the array holding the 16-bit data values.

I have been using different strategies to save (human readable) data into a text file, file the output is always:

System.UInt16[]

Any ideas on how to save my data?

Please use thread titles that best describe your problem. That challenges thing is an old trick which is a no no these days.
Post the code you used to print. Hopefully you did not print the array instead of the array contents ...
Nov 13 '07 #3
Plater
7,872 Expert 4TB
In this case ADData is an array of type System.UInt16.
So it's declaration would probably look like:
UInt16[] ADData;

But regardless, you need to loop through it, try this:
Expand|Select|Wrap|Line Numbers
  1. //this will loop through each entry in the ADData array
  2. for (int i=0; i<ADData.Length;i++)
  3. {
  4.    Uint16 val= ADData[i];
  5.    //write this value to a file
  6. }
  7.  

You can also use a loop style like this:
Expand|Select|Wrap|Line Numbers
  1. foreach(Uint16 val in ADData)
  2. {
  3.    // val contains the current value
  4.    // write this value to a file
  5. }
  6.  

So you would probably want something like this psuedo code:
Open file for writing data
Use one of the looping methods expressed above, writing each value to the file
Close the file (and filestream)
Nov 13 '07 #4
r035198x
13,262 8TB
In this case ADData is an array of type System.UInt16.
So it's declaration would probably look like:
UInt16[] ADData;

But regardless, you need to loop through it, try this:
Expand|Select|Wrap|Line Numbers
  1. //this will loop through each entry in the ADData array
  2. for (int i=0; i<ADData.Length;i++)
  3. {
  4.    Uint16 val= ADData[i];
  5.    //write this value to a file
  6. }
  7.  

You can also use a loop style like this:
Expand|Select|Wrap|Line Numbers
  1. foreach(Uint16 val in ADData)
  2. {
  3.    // val contains the current value
  4.    // write this value to a file
  5. }
  6.  

So you would probably want something like this psuedo code:
Open file for writing data
Use one of the looping methods expressed above, writing each value to the file
Close the file (and filestream)
How about making a generic Print method for all arrays?
In Java we have a neat Arrays.toString(T[] a). I suppose writing a generic one in C# should be a breeze
Nov 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: George Stout | last post by:
First off I do not know alot about writing queries to an Access Database from an ASP page. This is why I need help. I have an Events database for 6 colleges in our metro area. On the homepage I...
5
by: rob | last post by:
hey every1, I've got alot of data to write out to file and it's all just 1's and 0's. It's all stored in 2 dimensional arrays of width 32 and varying height. At the moment it's all just...
2
by: Jeevan | last post by:
Hi, I have an array of data (which I am getting from a socket connection). I am working on a program which acts on this data but the program is written to work on data from a file (not from an...
2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
2
by: simonc | last post by:
Is there an easy way of writing a number in 32 bit integer format into four bytes of a file? I am experimenting with FilePut but I can only make it work by defining a four byte array and doing some...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
2
by: totoro2468 | last post by:
Here is my code and output. Why is it writing to the array incorrectly, when I rewinded the file to the beginning? CODE: void ReadString (char *filename, int *lengthPtr) { FILE *ifp; char...
9
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
4
by: daqmaneng | last post by:
does anyone have any suggestions for writing a two dimensional array of data to a file. Currently, I have an array of 5 columns, with 1000 elements per array. I know that I can use a for next...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.