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
ADVERTISEMENT
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
Nov 8, 2013
Reading a .dat file, i'm unable to open the file. This program is for a Air Quality index detector, the AQI machine records the particle concentration every minute and saves it into new data file for each day. So I need to make this program run every minute and convert the concentration in to the AQI readings.
The filename is of the format "ES642_2013-11-09.dat", where ES642 is the software name of the machine, and rest is the year, month and day. The code here is just for the file reading section:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
[Code] .....
View 4 Replies
View Related
Sep 15, 2014
I've been trying to read a .txt into a linked list in the attached code. I'm running into problems, specifically I'm getting errors on line 41 (curr->word=charTemp. I'm trying to set the word array equal to the charTemp array. I've tried strcpy with no luck .
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
//Struct for linked list
typedef struct node {
char word[25];
struct node *next;
} node;
[Code]...
View 2 Replies
View Related
Nov 20, 2014
I have an *.lct file. I like to read *.lct file and save an bmp image.
I can not read this file using usual file read.
Code:
void CLCTtoBMPDlg::OnBnClickedReadlctfile() {
CFileException CFileEx;
CStdioFile ReadFile;
CString OpenlctfilePath;
TCHAR szFilters[]= _T("LCT Files (*.lct)");
CFileDialog fileDlg(TRUE, _T("bmp"), _T("*.lct"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
[Code]...
Find the attachment. change the file extension *.lct instead of *.txt. I like to read ASCII Data into Hex, Example : Data "A" as "41" (Refer the jpeg image). How is possible?
View 4 Replies
View Related
May 12, 2014
I am having trouble in reading data from my text file and print it out exactly like how it looks like in the text file. The problem im having is it will not read the last y Coordinates of the point. it keep reading the second last point for y coordinates which is wrong.
my text file is
0.0 0.0
0.0 1.0
1.0 0.0(but it read until here)
0.0 0.0(suppose to read the last point which is here)
For your information, this is my 1st year degree assignment in C programming. It is to create a program which can read text file (manually create) and print it out in a program and calculate the area for the polygon using ADT function ( .c and .h files)
*This is the code for my read file function*
Basically this accepts a Polygon and a file pointer as parameters. It reads the polygon point data from the file, pass the read data to plg_new() to create a new Polygon and returns the new Polygon created.
Code:
polygon *plg_read(polygon *New_polygon, FILE *Coord) {
int i;
int numberofvertices=0;
int count=0;
char filename[50];
double xCoor[50], yCoor[50];
[Code]....
This is the second function my polygon new code. This ADT function basically creates a new Polygon with malloc(), initialize all ADT data members with its parameter values and returns the Polygon.
Code:
polygon *plg_new(double *xCoordinates, double *yCoordinates, int numberOfVertices) {
int x;
polygon *New_poly = (polygon *)malloc(sizeof (polygon));
if(New_poly->xCoordinates == NULL || New_poly->yCoordinates == NULL) {
free(New_poly);
[Code]....
This is the rest of the code if you need to refer to other codings.
Code:
/**
*@file polygon.c
*@brief Functions for polygon / Struct has polygon numberOfVertices, polygon *xCoordinates and polygon *yCoordinates
*@author: Tan Xian Yao
*@id: 4323440
*@date: 22/04/2014
*/
[Code]...
View 6 Replies
View Related
Mar 12, 2014
I'm having some problems with Input to an array from a file. I think that i need to make a new array for every instance of the loop but i can't figure out how.
Participator class
void Participator::read(ifstream &stream){
getline(stream, name);
getline(stream, address);
stream >> paid;
}ParticipatorRegister class
void ParticipatorRregister::readFromFile(){
[Code]...
View 1 Replies
View Related
Mar 26, 2013
I'm having issues trying to input data from a .txt file into my array program. The whole program takes the name, # of goals and assists, adds them together to get points, and then puts in a given + or - rating. The program works except for the data input.
Also, this is an alphabetical "Unsorted" list, but is there a way to order the list based on point value and be able to display that as well as a separate "Ordered" list?
#include <iostream>
#include <iomanip>
#include <fstream>
#define NUM_PLAY 30
using namespace std;
int buildArrays(int[], int[], int[]);
void printArrays(string[], int[], int[], int[], int);
[Code]...
And this is the .txt file. Order is Players Name, Goals, Assists, Plus/Minus rating. The points are added when points = goals + assists (Should be in the main coding above).
Bryan_Bickell 2 5 +2
Brandon_Bollig 0 0 0
Dave_Bolland 4 2 -1
Sheldon_Brookbank 0 0 -1
Daniel_Carcillo 0 1 +3
[Code]...
View 5 Replies
View Related
Feb 13, 2014
Once it gets to string name = fileWrite.ReadString(); in write file it throws this exception about unable to read beyond the end of the stream.
static void Main(string[] args)
{
WriteFile();
ReadFile();
[Code]....
View 4 Replies
View Related
Jun 28, 2014
I started learning programming a few days ago and i'm having trouble with reading each line from a listbox this is the code i'm having trouble with
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string[] getFlies
{
get;
set;
[Code]....
What am I doing wrong?
View 5 Replies
View Related
Apr 23, 2014
This code works, but not fully This code reads com ports, when a string is available, I check to see if it contains some keywords defined in array If it does, i print out the string itself.
The problem i am having is that it seems to stop processing the data at some point but I do know that there are more strings to be read. So, it does keep reading more lines of data
using System;
using System.Text;
using System.Collections.Generic;
[Code]......
View 9 Replies
View Related
Jul 16, 2014
In a .h file there is a function that takes in this parameter:
void (^callback)(float * arg)=NULL
as in a function definition:
void func(void (^callback)(float * arg)=NULL);
What I am able to read is that it takes a function pointer and if not defined it overrides with NULL. The part I do not get is the ^ in (^callback). I only know ^ as a bitwise XOR operator. It also generates issues in my VS2012 compiler (something with CLR). So I would really like to rewrite this part to something else, without the bitwise operator...
View 2 Replies
View Related
Sep 23, 2014
I have been struggling to read a certificate in windows store from C++ DLL, but its not happening. from console application I can but when same code built as a DLL and tried to access from a separate console application. I think its not going to windows store to read the cert.
pCertContext = CertFindCertificateInStore((HCERTSTORE)*pCertStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_ISSUER_OF, operator PCCERT_CONTEXT(), pCertContext);
int Error = GetLastError();
if (Error == 0)
LINFO << "
Signtuare is valid
";
else
LINFO << std::hex << Error << '
' << "GetLastErrorStdStr=
" << GetLastErrorStdStr();
it returns 80092004 GetLastErrorStdStr= C a n n o t f i n d o b j e c.
View 1 Replies
View Related
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
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
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
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
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
View Related
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
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
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
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
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
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
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
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