C++ :: Code To Read 2D Array From TXT File

Apr 11, 2013

So the premise of my code is to read in a 2d array from a .txt. The array is a game board but the first two lines are what determine the size of the board. After i read it in i want it to find wherever te character "U" is, and then display the array but only showing U and whats around it. Problem is i cant get the array to print the right size and the code for displaying the U is not working either.

ifstream inputFile;
int boardSizeRow;
int boardSizeCol;
inputFile.open("C:UsersMichaelDesktopfileboard2.txt");
inputFile >> boardSizeRow;
inputFile >> boardSizeCol;
inputFile.get();

[Code]...

FILE:

20
20
WWWWWWWWWWWWWWWWWWWW
W GO W W
W WW w S W
W H W GW w W
WPW WW G W
WK W W
W W W W w w W
WK WU W
SW w w W
W W
w W G W
G W w W
D wwwww W
K w D W
w w W w w W
ww w WWWWWWW
G w W
ww w S w W
WWW G W
WWWWWWWWWWWWWWWWWWWW

View 5 Replies


ADVERTISEMENT

C/C++ :: How To Get Array Of Structure Code To Read Form A File

Dec 10, 2014

I tried to make the program read from a file text the first name or last name but o cant seem to get it. i tried alot of different ways. how can i get the array of structure code to read form a file?

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
const int NUM_STUDENTS = 17;
const int NUM_QUIZZES = 10;
const int NUM_EXAMS = 5;

[Code] .....

View 14 Replies View Related

C :: Error While Using Struct In Code To Read From File

Jan 31, 2014

I am trying to use struct to store variables from a text file and use them in the main program. I have first tried running the program without using struct and declaring the variables within the main program and it runs fine. But after using struct, it gives no compilation error and a segmentation fault as output. Also, if the size of file/variable size is unknown can I declare variables as char string[]??

The code is as below:

Code:

#include<stdio.h>
struct test {
char string1[10000];

[Code].....

View 4 Replies View Related

C/C++ :: How To Reuse Existing Code To Read Data File In Qt

Aug 13, 2014

I've got some code in C++ that does some basic analysis on price data and I run it from the cmd prompt. One of the functions I had built to read in the data is as follows:

void ReadPricesFromFile(constchar*filename,std::vector<PriceInfo>&prices)
{std::ifstreaminput(filename);
input>>prices;}

How would one merge this type of code into a Qt GUI? Ideally, I'd like to use something like QFileDialog to open up a folder with my data files, select a file, and then read the file that the user selects. Would the main.cpp look something like this?

int main (int argc, char *argv []) {
QApplication prog (argc, argv);
QPushButton *load_button = new QPushbutton ("Load File");
QObject:: connect (load_button, SIGNAL (clicked()), &prog, SLOT ( (ReadPricesfromFile function?);
load_button-> show ();
return prog.exec ();}

View 3 Replies View Related

C# :: Read Data From More Than One File At Once - Not All Code Paths Return A Value

Apr 11, 2015

I am trying to read data from more than one file at once. The files are different types e.g. one is a text file one is an xml file like so, StudentInformation.txt, CollegeInformation.xml. The files are all stored in one place, in this case on the D drive of a local computer. I am trying to locate any files in the D drive with a file extension of .txt or of .xml (there may be more than two of these files in the future, so I'm trying to allow for that). Then I want to open all of these files, extract the information and output all the information in one display window. I want all the information from these two or more files to be displayed together in the display window.

Here is the code so far. It is throwing up errors.

//Load from txt files
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
IEnumerable<string> fileContents = Directory.EnumerateFiles("D:\", "*.*", SearchOption.TopDirectoryOnly)
.Select(x => new FileInfo(x))
.Where(x => x.Extension == ".xml" || x.Extension == ".txt")
.Select(file => ParseFile(file));}

[Code] ....

The error it throws up is:
Error 1 'BookList.Mainwindow.ParseFile(System.IO.FileInfo)': not all code paths return a value

View 2 Replies View Related

C++ :: How To Read A File Into 2D Array

Nov 15, 2014

I'm finishing up my first semester as a Computer Science major, but I'm struggling with programming.

I need to read a file into a 2D array.

Here is what the file contains (90 characters):
S
R
R
S
R
R
R
R
S
....

Here is my current code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

View 4 Replies View Related

C++ :: Read A File And Put In A Array

Jul 4, 2013

I need to do a program that reads a file, that contains something like this:

8 2 3 4 2
5 6 1 3 4
3 1 4 6 7
7 2 4 1 3
3 2 1 6 8

and put in a array[][] in the program..I did this:

int main(){
using namespace std;
int size=0;
char line[1300];
FILE *file;
char path[50];
int l=0,c=0;

[code].....

But when i print A[3][3], it does not contain the correct value, but I strange value, like -36893488147419103000 .My idea was to pass line by line of the file, including the values that were not " ", to get only the numbers.

View 2 Replies View Related

C :: Print Out - Array Code And Pseudo Code?

Apr 15, 2013

I have assignment which requires me to print out and array code and a pseudo code. I dont no what a pseudo code is,.

View 2 Replies View Related

C++ :: Can't Read Floats Into 2D Array From File

Apr 11, 2014

I can't get the values correctly parsed.

Code:
float **get(int sizeX, int sizeY) /* Allocate the array */ {
float** ary = new float*[sizeX];
for(int i = 0; i < sizeX; ++i)
ary[i] = new float[sizeY];
return ary;

[Code] ....

test.txt (without the comments).

Code:
2 3 // columns and rows of 2D array
0 0
1 1
2 2

View 3 Replies View Related

C :: Unable To Read TXT File Into 2D Array

Jan 30, 2013

here is my code, I'm trying to read a .txt file into a 2D array... what's wrong with my code?

Code:

#include <stdio.h>
#define INPUT_FILE_GET_NAMES "names.txt"
#define INPUT_FILE_GET_SALES "sales.txt"
#define MAX_ROWS_NAMES 25
#define MAX_COLS_NAMES 20
#define MAX_ROWS_SALES 25
#define MAX_COLS_SALES 6
//Function Declarations
char getNames(char namesArray[][MAX_COLS_NAMES], char filename[]);

[Code]...

View 1 Replies View Related

C++ :: How To Read Data From TXT File Into Array

Feb 25, 2013

I wanna read a txt file like this
1.00518 2.01903 3.01139 4.01343 5.02751 5.99913 7.00011 7.99851 .....
and fill the array P[i][j] with the data.

I try to use

if (myfile.is_open()) {
//for (int i = 0; i < 1; i++)
//{
getline (myfile,DMArray[0]);
cout << DMArray[i] << endl;
//}
myfile.close();
}

But this read the data into a string. How should i do with this string. Besides I know the dimension of the data I am reading.

View 1 Replies View Related

C/C++ :: How To Read And Analyze Code

Jan 21, 2014

Am I doing this correctly? My assignment is pretty much to answer certain codes manually.

int i = 0;
while (i < 7 )
{
cout << 2 * i;
++i;
}

Does this code read as

2 * 0 = 0
2 * 1 = 2
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12

How about the ++i part?

View 5 Replies View Related

C :: How To Read A Text File Into Array Of Strings

Mar 3, 2013

In a program, I have a text file (called MyDictionary.txt) which has thousands of words in alphabetical order. I need to make a C program that reads in this text file and then makes an array called char Words[# of total words in the text file][length of longest word].

Aarhus
Aaron
Ababa
aback
abaft
abandon

View 6 Replies View Related

C++ :: Read A File Into 2D Array And Display Data

Nov 15, 2014

I am currently working on a problem where I read a file into a 2D array, and display data. If you saw my code earlier, this is the same problem, but I am now further along.

The file (90 characters) looks like this:
S
R
R
S
R
R
R
R
S
S
....

The "R" resembles rainy days, the "S" resembles sunny days, and the "C" resembles cloudy days. There are 90 characters in the file. The first 30 are for the month of June, the next 30 are for the month of July, and the last 30 are for the month of August. The 31st day of the months are NOT included.

I read the data into a 3 x 30 array, where the row indicates the month (0 = June, 1 = July, 2 = August) and the column indicates the number of days in each month.

Now I need to create a function that creates a report and displays, for each month AND for the whole 3 month period:
1) The number of rainy days
2) The number of cloudy days
3) The number of sunny days
4) Which of the 3 months had the largest number of rainy days

Here is my code so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int MONTHS = 3;//Number of months

[Code] .....

There are no compiling errors, but I am not getting the data I want. My rCount and cCount variables end up being 0, and my sCount variable is 90.

View 4 Replies View Related

C++ :: How To Read Information From Text File To Array

Apr 4, 2014

Perhaps my original wording on this was confusing so I will ask a different way.

if I have a text file called

data.txt

and it has the following in it.

12345
67890
12345
67890

how would i read this information into an array called

int data[4][5]

This is in C.

View 10 Replies View Related

C++ :: Read From A File And Place Data Into Array

May 3, 2014

Assume you want to read from a file and place the data from the file into an array. The array can hold 10 integers. The file may contain any number of integers with 1 integer per line. Fill in the missing loop test condition so that we will read from the file until either end of file occurs or the array is full. Note we are using cin to read from the file since input redirection is being used.

cin >> temp;
arrayIndex = 0;
while ( _____________________________________) {
array[arrayIndex] = temp;
arrayIndex++;
cin >> temp;
}

View 2 Replies View Related

C/C++ :: Determining Length Of Array Read From File

Feb 16, 2015

i have to read a file with between 5 and 10 pairs of numbers, each on a different line. i can read the file, and wrote something to save the length of the file as a variable, but when i use it i start returning crazy data. the problem is in the do while loop and i want to change the i< in the for loop to "lines" so the code stops when the last digit is read. if i use i<10 the file has extra digits is the file is only 8 or 5 pairs of numbers.

FILE *Fpointout;
FILE *Fpointin = fopen ("test.txt","r"); //read this one
Fpointout = fopen ("out.txt","w"); //write this one
if (Fpointin == NULL) //if no file in source {
printf ("File does not exist."); //tell user it is not there

[Code] .....

View 4 Replies View Related

C :: 1D Dynamic Array Crashes When Read From File Into A Function

Mar 17, 2014

code:

/part of main function
int *A=NULL;
//load from file
load_from_file(A, &next);
printf("next=%d
",next);
getchar();
printf("A[%d]=%d
",0,A[0]);getchar();//here program crashes
}

[code]....

I initialize array A with NULL in main, and I "load" it with elements from a file. The code without function is working. But when I tried to use a function as above, my array crashes!!!

View 4 Replies View Related

C++ :: Unable To Read Data File From Two Dimensional Array

Apr 27, 2014

I am new to C++ and I am having an issue reading in a 2 Dimensional array from a data file. I am very close to reading it in perfectly except for one issue, the loop is ignoring the first value from the data file.

This is the code I have so far:

#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <functional>
#include <conio.h>
#include <iomanip>
#include <string>
#include <fstream>

[Code]...

This is the values from the data file:

300 450 500 210
510 600 750 400
627 100 420 430
530 621 730 530
200 050 058 200
100 082 920 290

When the Program shows my array it comes up as:

450 500 210 510
600 750 400 627
100 420 430 530
621 730 530 200
050 058 200 100
082 920 290 0

Every array location is moved up one, like the program just completely ignored the 300 at the beginning.

View 1 Replies View Related

C++ :: Read A Text File And Store Contents Into 2D Array?

Aug 2, 2014

read a text file and store the file contents into a 2D array?

100 101 102 103 104 105
106 107 108 109 110 111
112 113 114 115 116 117
118 119 120 121 122 123
124 125 126 127 128 131

Here's my code:

const int ROWS = 5;
const int COLS = 6;
int array[ROWS][COLS];
ifstream inputFile;
inputFile.open("table.txt");

[code]....

When i run the program and try and display the array, it doesn't work.

View 1 Replies View Related

C++ :: Sort Data From Text File Into Array As Its Being Read?

Feb 12, 2013

I am suppose to make a program that reads in data from a text file (integers only) and sorts them as it inserts them into an array of size 10. I did this using an insertion sort, which worked great. But now I am being told that I need the function has to read ALL of the numbers in the text file, not just the first 10, and I am not allowed to store them THEN sort, it has to be sorted as being stored.

This is what I have for sorting first 10

void sortArray(int iArray[])
{
string fileName = "";
fstream inFile;
int tmp = 0;

[Code]....

View 3 Replies View Related

C/C++ :: Read Dictionary File Into Array And Check Spelling?

Jan 27, 2015

finishing my program which needs to do the following:

(i) Write code to read in the dictionary into an array of words

(ii) Write code to check the spelling of a word entered by the use

(iii) Like Scrabble / Countdown the user enters the letters they have and my code must find the word using the highest number of those letters

I have completed a good bit so far but I'm stuck on my checkSpelling() and findWord() functions as well as part (iii)

#include "stdafx.h"
#include <stdio.h>
#include "string.h"
int countCharOccurence(char *string, char c);
int getOption();
int checkSpelling();

[Code]....

View 3 Replies View Related

C/C++ :: Read Strings From File And Place Into Multidimensional Array

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

Visual C++ :: Read Excel File And Storage In Array

Nov 4, 2014

I wish to read an excel file which contains the table shown at the picture below.

I don't really know how to code the direct storage of the values in the appropriate array.

For example I wish to store the countries in an array of a string type.

could I have some piece of code which illustrates it (I mean the reading of an excel file and the direct storage of his value in an array).

View 1 Replies View Related

C++ :: How To Get Code To Read Multiple Input Values

Feb 10, 2013

So I have to write a code for my C++ class, and I am having a problem trying to figure out how to get my code to read multiple int values. This is what my code should look like

Enter two times in military format (e.g., 1730 1520): 1730 1520
[1520<1730]
Enter two times in military format (e.g., 1730 1520): 1520 1730
[1520<1730]
Enter two times in military format (e.g., 1730 1520): 1730 1730
[1730==1730]
Enter two times in military format (e.g., 1730 1520): 1760 1520
1760: [INVALID TIME 1]
Enter two times in military format (e.g., 1730 1520): twelve 2
[INVALID NUMERIC INPUT]

View 1 Replies View Related

C Sharp :: Code To Burn And Read Files From CD ROM

Jan 9, 2013

how can i burn and read data from cd rom in c# language.???

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved