C# :: Parsing Save File Into Multidimensional Array
Mar 26, 2015
I have this file that I would like to read into a multidimenstional array in c#: file. If I take the first set of lines as a first example, I would like the print_r to look something like this:
Array (
[SiiNunit] => Array (
[0] => Array (
[nameless.2BB8.4FB8] => Array
[0] => Array (
[bank] = _nameless.2917.43B0
[player] = _nameless.2813.6928
[companies] = 312
[code].....
this (as I expected it to) wrote each line of the file into a 1d array however, I would like it to write it to a multidimensional array.
View 7 Replies
ADVERTISEMENT
Nov 30, 2013
For a rather complex and strange reason that I won't explain right now, I need to have this going on in my program.
class FVF{
private:
vector<vector<float>> data; //Contains fvf data for Direct3D stuff
public:
[Code].....
The FVF allows this Model3D class to also be compatible with file handling methods I've got, but here's the problem. D3D buffers require an array to feed them the information, and I know that for a single dimension of vector I can use vec.data(), how to do this for multiple dimensions.
I think the best Idea I've got so far is to set the vector within the Model3D class as a pointer, then I can union it with a float pointer... Once I can guarantee the information is correct and complete, manually transfer the contents of the vectors into the float pointer.. (The union is to reduce memory needed instead of having the data repeated in vectors and arrays)
how I could just pass these as arrays?
View 4 Replies
View Related
Mar 1, 2014
I am having problems figuring out how to place a list of strings from a text file into a multidimensional array that is something like words[NUM_WORDS][MAX_LEN]. I already run through the file once and count the number of words in it. I have tried a number of loops using fscanf and fgets, but I'm not sure if I am using them right -- this is my first time using them. The text file is a list of words in a dictionary, so the wordCount is about 45340.
Here is my code:
#include <stdio.h>
#include <string.h>
#define MAX_LEN 46
int main(){
int wordCount = 0;
FILE *inputFile, *outputFile;
[Code] ....
Like I said, the wordCount portion works. I added the printf statements at the end to see if anything was being saved, but it just prints two new blank lines. New to file reading and writing.
View 3 Replies
View Related
Nov 5, 2013
I am trying to develop a GUI using MFC, but I am having trouble using CFiledialog to save a file. The problem is, the file is not getting saved to the folder when I use the CFiledialog. Below is the code I am using.
Code:
CString szFilter = "XNRep Files (*.xnrep)|*.xnrep||";
CString s = "xnrep";
CString t = "";
CFileDialog fileDlg(FALSE, s, t, NULL, szFilter);
if(fileDlg.DoModal() == IDOK)
{
std::ofstream file;
[Code]....
After the file dialog opens up, I enter the name of the file and select OK button. But the file does not show up in the directory I am saving to.
View 4 Replies
View Related
May 28, 2013
I wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.
decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.
whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?
Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/
#include <stdio.h>
#include <stdlib.h>
[Code] ....
View 4 Replies
View Related
Feb 27, 2013
I have a multidimensional array that runs parallel with a string array
Lincoln 120 300 400
Parks 100 500 250
Shakespeare 0 30 50
Ghandi 250 100 40
Ashe 300 50 175
Rodriguez 87 118 320
Curie 284 0 112
I need to sort this and I know how to do it. But I need to sort it again with the highest value in the first row and keep all information in that row paired with the name . So
Lincoln 120 300 400
Parks 100 500 250
Parks 100 500 250
Lincoln 120 300 400
I need so swap this whole rows. I'm using dynamic array. So my question is Do I have to do a bunch of temps to move them? Or is there a way to move the whole int array row as a single unit?
View 3 Replies
View Related
May 6, 2013
I have some cpp code that is looping through an array of char looking for a delimiter. The code saves the chars in a string until it finds the delimiter, then it adds the string to a vector of string and continues processing.
The input char array is,
Cl.N1C=CC=N1.HCl
the delimiter is '.', so the parsed strings should be,
Cl
N1C=CC=N1
HCl
The code seems to work find for the first two strings, but then it seems to stop and not find the third string.
This is the code,
Code:
#include <iostream>
#include <vector>
#include <string>
[Code].....
...then nothing. The function returns to the calling code, but may not have returned normally, it is hard to tell.
This appears to work up to a point, but does not find the last string HCl. The size of the char array that is passed to the functions prints as correct (16), so the for loop should process all 16 characters in the array. I don't see here why it stops.
This was compiled using g++-3. Some of the unusual syntax results from this being a cpp function that is called from fortran. The char array that is passed to the cpp prints as correct and has the correct size, so I don't think that is part of the problem.
View 5 Replies
View Related
Jan 13, 2015
Problems :
1) Is there any way so that i can use "X" and "O" char instead of 9 and 0 int.?? I also tried to use enum but was only able to print out -1 for 'X' and 0 for 'O'...
2) if player - 1 choose field 2 . and player - 2 chooses field 2 .. how can i show error and ask for another input ?
3) is there any short coding trick for int check_result(); ?
Code:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
[Code] ....
View 3 Replies
View Related
Jul 31, 2014
What is the correct method of declaring pointer to multidimensional array
Code:
int array[3][4];
int *p = array;
The above code works but it shows warning. Is it an invalid way of using the pointer? the array is an address then why am i getting warning?
View 1 Replies
View Related
Sep 25, 2013
I'm trying to pass a two-dimensional array to a function. The function is defined as: long foobar(char foo[][CONST]); I have to create that array dynamically. Currently I do that this way: char* bar = new char[count * CONST];
But when I'm trying to pass the array I get a type conversion error. I tried a lot of different ways to pass the pointer and/or to allocate the memory, but apparently I didn't find the right way or combination of definition, allocation, casting and calling.I cannot change the definition of the function, which (IMHO) is pretty stupid. :(
View 3 Replies
View Related
May 1, 2015
I have put aside C++ for a while. And I am back to it.
I forgot how to return a 2 dimensional arrays from a method?
Code:
Node** GetNodeMap() const { return m_Nodes; }
private:
Node m_Nodes[60][60];
How can I achieve that?
View 5 Replies
View Related
Apr 11, 2014
I'm parsing an xml file full of payslips and using the data in another application. I've got it all working but I suspect it isn't the most elegant piece of code. I run through the xml file finding a series of "Text" attributes/elements" and then I run through it again finding a series of "Field" attributes/elements, Here is a sample of the code:
For getting the "Text" fields :
XNamespace ns = "urn:crystal-reports:schemas:report-detail";
//
// Get all the Text attributes & Elements
//
foreach (XElement xtxt in xdoc.Descendants(ns + "Text"))
[Code]...
This works fine, I extract all the data I'm interested in and go to do my thing with it. However I really need to know when each record ends and I was doing that by looking for "Text24" in the text fields and "EeRef2" in the field fields, which wasn't very elegant in the first place. Then a "Text16" was added to end of each record which was fine I could just look for "Text16" but now it's apparent that "Text16" isn't always there. I've got it all working for now but I'd prefer to process one record at a time i.e. extract all the "Text" & "Field" values for one record, do whatever I need to do with it, update the xml file to indicate this progress ( if possible ) and then move on to the next record. I've attached a sample of the xml but basically is has the following structure :
<Details>
<Section>
<Text></Text>
"
<Field></Field>
[Code]...
So a record is everything between the first <Details> and the last </Details> with two <Details> and two </Details> in between.
View 2 Replies
View Related
Nov 24, 2013
Working on this one from the Jumping into c++ book. The book asks that I create a multidimensional array at run time based on user input and fill it with a multiplication table
My code compiles fine but throws an uninitiated error for p when I try and run it.
Code:
void multiDimentionalMultiplication(int x, int y, int z){
int ***p;
**p = new int[x];
std::cout << "Allocating array.
[code]....
View 8 Replies
View Related
Mar 19, 2014
I have initialized a multidimensional array eg char fruit[5][10]...Then I would need to read in 3 words with spaces in between from user and store in fruit[5][10] e.g "pear apple orange"
The thing is that after typing orange, when I press Enter it still prompts me to enter more characters. How can I end the scanning of characters after orange ?
View 4 Replies
View Related
Feb 27, 2015
I have a 3-dimensional matrix(3,3,3) and want to write it to a file. I have the code for parsing it in a compatible for matlab format. But at this point i want to use a pointer to do the same thing.
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
const int dimx = 3, dimy = 3;
int i, j;
unsigned char a[3][3][3] = {
[Code]...
If it is a 1-dimensional array i can understand the logic.
Code:
int val[7] = { 11, 22, 33, 44, 55, 66, 77 } ;
int *p;
p = val[0];
for ( int i = 0 ; i <= 6 ; i++ )
[Code]...
View 3 Replies
View Related
Mar 26, 2013
I know how to find a specific number in a multidimensional array, but I don't know how to have a specific number and find its coordinates.
View 2 Replies
View Related
Nov 15, 2014
In one of my programs I have a 3x3 array of string that I use to display the outcome to rock, paper, scissors, and another 1x3 used for a number guessing game. I have the arrays declared in the header file as follows:
//Games.h
std::string rpsOutcome[3][3];
std::string hiLoOutcome[3];
and then initialized them in the cpp file:
//Games.cpp
string rpsOutcome[3][3] {
//row 1
{ "Both of you picked rock, you tied. Try again",
"You picked rock, the computer picked paper, you lose",
[code]....
From what I've read, Im pretty sure thats how your supposed to initialize multidimensional arrays (using the nested braces), but when I build the project, I get the following error:
123456789101112
1
1> RockPaperScissors.cpp
1> Games.cpp
1>c:userswuubbgoogle drivevisual studio projectsgamesgamesgames.cpp(75): error C2374: 'games::rpsOutcome' : redefinition; multiple initialization
[Code] .....
View 4 Replies
View Related
Feb 12, 2013
In the code that I am working on I am generating random numbers and assigning them a 2d array. But when I output the array in a separate nest of for loops the values are incorrect, but if I output the array in the same nest of for loops the values are correct
int spot[4][4];
int range[] = {1,16,31,46,61}, held[4];
void Generate() {
for (int y =0; y<=4; y++) {
for ( int x =0; x<=4; x++) {
spot[x][y] = (range[x] + rand() % 15);
[Code] ....
View 3 Replies
View Related
Nov 16, 2013
I am trying to unroll the inner i and j loops within this multi-dimensional array which spits out a block image. Unfortunately, the image does not match the color of the original image probably because filter->get(i,j) gets altered in a way that I don't want it to.
double
applyFilter(struct Filter *filter, cs1300bmp *input, cs1300bmp *output) {
long long cycStart, cycStop;
cycStart = rdtscll();
output -> width = input -> width;
output -> height = input -> height;
[code]....
View 3 Replies
View Related
Feb 11, 2013
void printMatrix(int x[][]){
cout << "Matrix " << x << ":" << endl;
for(int r=0;r<rows;r++){
for(int c=0;c<colums;c++){
cout << x[r][c] << " ";
} cout << endl;
}
}
Error: declaration of 'x' as multidimensional array must have bounds for all dimensions except the first
How can i use multidimensional array with unknown bounds?
View 1 Replies
View Related
Apr 10, 2012
After passing the address of the first element (&array[0][0]) of a multidimensional integer array to a function with a "const int*" parameter, parameter seems to be pointing to the wrong values, which are not the actual elements of the passed array.
First, why does this happen ?
Second, how can I fix this without changing the parameter type into a multidimensional int array ?
View 4 Replies
View Related
Sep 28, 2013
I am currently trying to write a program, which i able to print a multidimensional array using classes. My problem is, it prints random values, and not the value from the user input.
Here is the Code
[URL]
View 1 Replies
View Related
Feb 10, 2013
I have a massive text file containing many thousands of directory and file names with / at the root, like so:
/dir/
/dir/dir/
/dir/dir/dir/
/file
/dir/file
/dir/dir/file
/dir/dir/dir/file
I need to parse the file in such a way that I can create a filesystem hierarchy as if I were enumerating files/directories. Ultimately I want to add these to a tree gui control with everything under its proper node without duplicating anything. It should look roughly like so:
dir
-file
-dir
-file
-dir
-file
I can open the file and add nodes/children to the tree control but how should I go about doing the actual parsing? How can I find a filename and say "this belongs under this node"? I want to do this efficient as possible even if I must use multiple threads.
View 1 Replies
View Related
Aug 26, 2014
Requirements in filtering the text file.
1. first my professor required me NOT to change the MAIN function(because he made it)
2. I have to make 3 getlogs() STRING FUNCTIONS:
a. string getlogs(); - accepts no paramters, SHOWS ALL THE CONTENTS OF TEXT FILE
b. string getLogs(const string & a); - accepts 1 parameter -SHOWS ONLY THE LINE WHICH CONTAINS THE SPECIFIED DATE FROM MAIN FUNCTION which is "2014-08-01"
c. string getLogs(const string & b, const string & c); - accepts 2 parameters, SHOWS ONLY THE LINES FROM THE DATE START to DATE END specified at THE MAIN FUNCTION which is date start-"2014-08-01";DateEnd = "2014-08-10";
3. all COUT should be in the MAIN FUNCTION
TEXTFILE CONTAINS:
2014-08-01 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-03 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-04 06:13:14,Name,4.5,CustomUnit,CustomType
[Code] .....
my codes so far:
//MAIN
#include <iostream>
#include <string>
#include <fstream>
#include <dirent.h>
[Code].....
View 1 Replies
View Related
Aug 13, 2014
From the example given below, I would like to Generate a matrix who stores a generated array for each iteration. I have an understanding of inputting single elements to a matrix but how can I input an array to a matrix. let's say I would like to input and array of 4 elements that should be stored as a single row of the generated matrix and do this for an infinite while{true} loop.
#include <iostream>
#include <unistd.h>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
void printArray(int arr[], int size) {
[Code] ....
View 7 Replies
View Related
Jul 31, 2013
How can I Passe some part of multi-Dimensional Array to a Function; for example only two dimension of three dimension of a an array with 3 dimension. This is because my function is defined for working with 2 dimension arrays.
View 3 Replies
View Related