C# :: Convert Dictionaries To Arrays To Read And Write Sequentially
Nov 27, 2011
Code:
// declare child arrays
public string[,] childcolor;
public string[,] childgeneo;
// create dictionaries
public Dictionary<string, int> colors = new Dictionary<string, int>();
public string color; // name for dictionary
public Dictionary<string, string> geneo = new Dictionary<string, string>();
[Code]...
I'm getting "field' is used like a 'type' error on jw.childcolor which causes other parts to error out.
How do I fix this & why am I getting the error?
I want to convert the dictionaries to arrays to read & write sequentially.
reading and writing 2D arrays I've been trying out a few tutorials using FileStream but I couldn't get any of them to work.
Anyway what I'm trying to do is save the playerArray to a .txt file and then read from that .txt into the fields within the GUI. This is supposed to act as a database.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
I want to sequentially remove one element at a time starting with the first. When the second element is removed, the first element needs to go back in. The sequence would look like
Code: // original vector, row_numbers.size()=9 row_numbers{1,2,3,4,5,6,7,8,9}; // trimmed vector, row_numbers_trim.size()=8
[Code] .......
I have been working under the assumption that the best method would be to have row_numbers remain untouched and work on a copy. For each step in the sequence, you would create row_numbers_trim as a copy of row_numbers, and then remove an element from row_numbers_trim.
Code: // position being removed int counter = 0; // copy original vector row_numbers_trim = row_numbers; // remove the first element from the copy row_numbers_trim(row_numbers_trim.begin()+counter);
All you would have to do here is to increment counter in a loop. is there a better way?
We have a program that sequentially processes a large number of files (currently about 700 expected to increase to about 1500). The program performs the same processing on each file (and doesn't involve any other file) which is io-bound and not cpu-bound. This process takes several hours and it is normally performed overnight.
I've refactored the program so that the processing for each file is done within its own thread (ie one thread created for the processing of one file). This gives rise to many hundreds of io-bound threads. This refactored program is working with no errors reported and has reduced the total processing time down to about 10 minutes.
Any problems that might arise having this number of threads (700 to 1500) created/running?
My tasks was to write a program which finds difference between two arrays (elements which are in first array but not in second and vice-versa). Program works, but something wrong is with the memory allocation for array.
My code is: main.c Code: #include <stdio.h> #include <stdlib.h> #include "header.h"
Using PIONTER NOTATION ONLY, write a function that receives two arrays of integers like A and B above. The function should swap the values in A and B. You may NOT use array notation [ ]. Also, you have to use pointers to move among array cells. Note: Both arrays are of the same size, and size should be variable in the function.
SO Im supposed to write a program that uses arrays to calculate the sum and display it. I keep getting the error that says the sum has to be initialized.
#include <iostream> using namespace std; //Function prototype int sumArray(int); const int NUM_ELEMENTS = 5;
Place the even lucky numbers in an array called evenList, the odd lucky numbers in an array called oddList, and the negative lucky numbers in an array called negList.
//So in main main i passed the array as parameter and the size;
void lucknumberlist(int favnum[], int size) { int even = 0, odd = 0, neg = 0; int evenArray[even]; int oddArray[odd]; int negArray[neg]; if(favnum[even] % 2 == 0) { evenArray[even] = favnum[even];
My program needs to receive data continuously from one process and the received data is read continuously by another process.But when I am trying to create a pipe using mknod on fat32 file system in linux , it throws an error saying "mknod: operation not permitted".
I receive a telegram in XML format and I need to parse it and send my data in the same format back. My main problem is that I'm not allowed to use any open source software or other 3rd party software except VS2010. I have to write it in C++.
Now my question: is there any good tutorial for such a parser? I was hoping that I could write something which can be used similar to the GEtPrivateProfil-functions which are handy for ini-files.
i'm trying to write a calculator. the user will enter the terms and they will be stored in arrays. i will be storing those terms in string arrays and then later turn them to double to work with them. but the user should be able to enter terms like sin(252) and the program should be able to recognize it and calculate it.
I am trying to rewrite a matlab code into c++. It reads a file and do the deresolution on it and convert it to 8 bit.
but the VC++ code does not work for all ranges of max_den and min_den. Specially when the there is a small difference between them. (I tried that range on Matlab, it works)
MATLAB Code:
fid = fopen(ORIGINAL_FILENAME,'r'); A = fread(fid,X*Y*Z,'int32=>int32') D = uint8(255/double(Maximum_Density-Minimum_Density)*(A-Minimum_Density)); A = reshape(D,X,Y,Z); fid=fopen(OUTPUT_FILENAME,'w');
[code].....
For example when actual range of data is [-3023,3072] and the max_den=-3000, min_den=1000, it works well. but when you choose max_den=-1000, min den=1000, it doesn't work properly.The raw file includes 3D data associated with a mhd file. When the range is not wide enough, the converted file becomes messy.
this is my read/write functions based the read from the last post! then went nuts with it! used the %19s%*s on the write to the file, solved all the probs on the read side! but any refining on this would be great. This is another program that i started with the forums, and started going my own direction!
1. Design 1: Have an independent class to handle everything and "friend" it with the users. Pro: Only 1 interface needed and we can switch interface easily. Con: There is a lot of inter-class data which destroys encapsulation
class CalibratorXML; class Device{ string sourceLabel; string destLabel; vector<CalPoint> calPoints; friend class CalibratorXML;
I'm looking to write a program in C/C++ to traverse a Fasta file formatted like:
>ID and header information SEQUENCE1 >ID and header information SEQUENCE2
and so on
in order to find all unique sequences (check if subset of any other sequence) and write unique sequences (and all headers) to an output file.
My approach was:
Prep: Copy all sequences to an array/list at the beginning (more efficient way to do this?)
Grab header, append it to output file, compare sequence for that header to everything in the list/array. If unique, write it under the header, if not, go on.
However, I'm a little unsure as to how to approach reading the lines in properly. I need to read the top line for the header, and then "return?" to the next line to read the sequence. Sometimes the sequence spans more then two lines, so would I use > (from the example above) as a delimiter? If I use C++, I imagine I'd use iostreams to do the reading.
How to read some characters from file, I know we can move a pointer to some position using seekg() & seekp() function, get current position of the pointer through tellg() & tellp() functions. By moving the pointer to appropriate position using seekg(), we can read the whole line using getline() function. But is there any function which read certain characters from the current position of the pointer and write certain characters from current position of the pointer.
How to read some characters from file, I know we can move a pointer to some position using seekg() & seekp() function, get current position of the pointer through tellg() & tellp() functions. By moving the pointer to appropriate position using seekg(), we can read the whole line using getline() function. But is there any function which read certain characters from the current position of the pointer and write certain characters from current position of the pointer.
int main () { FILE * pFile; long lSize; char * buffer; size_t result; pFile = fopen ( "myfile.bin" , "rb" );
[Code] .....
How to open binary for read and write? Why the buffer is char * buffer? i mean in binary u cant read chars . How can it be? how the data is represented? just like txt file? What the buffer will contain how to print this buffer???
Explain me a working code to read and write a file using serial communication.and i need to store that file.I know normal file handling in C, but how it is through serial port i am not getting.
I'm not sure if I should do this with malloc or a char array. What I need to do is create 4 methods to read and 4 to write to memory like this (and it has to be fast):
Code:
char GetByte(char* memory, int offset); uint16 GetInt16(char* memory, int offset); uint32 GetInt32(char* memory, int offset); char[] GetString(char* memory, int offset);
So basically memory is the malloced memory and the offset is the position I want to read at.
I'm not sure if there's already a way to do this and maybe I'm overlooking something.