C++ :: Finding Char Array In A Large File

Feb 21, 2015

I have a specific byte (that is unsigned char) array, that I need to find in a very big file (2GB or so), currently I'm using:

size_t fsFind(FILE* device, byte* data, size_t size) {
int SIZE = (1024 > size) ? 1024 : size;
byte buffer[SIZE];
int pos = 0;
int loc = ftell(device);

[Code] ....

Which seems to find proper result on first use, but on subsequent searches it seems to find invalid positions, is there something I'm doing wrong, or is there a better way?

View 6 Replies


ADVERTISEMENT

C++ :: Finding If A Number Is Prime - Large Numbers

Sep 15, 2013

I have a very large number in word ~6million digits long

I wish to make a program to check if it is prime.

View 5 Replies View Related

C++ :: Reading In Text File Into Char Array

Oct 17, 2014

I have a project which is about linked lists in the order of: a Story is made of Paragraphs which is made of Sentences which is made of Words. We must treat Words specifically as character arrays, not strings. So I need to read in a story from a text file and make Words by finding the first whitespace/punctuation(everything before the whitespace up until the whitespace or punctuation is the Word), all the Words up to the punctuation are a Sentence (Sentence is a linked list of Words), Paragraph is all the Sentences up until an empty line, and a Story is all the Paragraphs. So I know doing this will let me take a line and put it into a character array:

char charArray[25]; //we are allowed to assume a word won't be longer than 25 characters
int i = 0;
ifstream myFile(fileName.c_str());
if(myFile.is_open()){

[Code].....

I suppose I could look at charArray[i] and if it is ws or punctuation then make the Word = charArray[i-1], but is there an if statement I could do that would prevent the ws or punctuation from being read into charArray in the first place? Because a problem I see with the charArray[i-1] method already is that "This is a story." would get put into the array as Thisisastory. and thus I'd be unable to break up at a space.

So to summarize: I want to read in a text file character by character into a char array, which I can set to length 25 due to context of the project. I want to read in each character and at a whitespace or punctuation, I want to take everything already in charArray and feed that into a Word object constructor (the next Word gets linked to the previous Word, and at a punctuation all the Words linked together become one Sentence, and all the Sentences linked before an empty line become a Paragraph, etc). So how can I get charArray to be only characters in a word, then after the word being read-in ends, charArray resets to empty, and then is populated by the next word and so on.

View 2 Replies View Related

C/C++ :: Reading Strings To Char Array From Exe File

Feb 25, 2014

I am trying to read strings to an char array from an .exe file and then i would check some of the strings, but the problem is that the only thing that is read from the file is the first string (MZ) and an 'square' that is some incorrect character. I am using fread to read from the file. Here is my code:

FILE * pFile;
long lSize;
char * buffer;
size_t result;
pFile = fopen("my_file.exe", "rb");
if( pFile == NULL) exit(1);
fseek(pFile,0, SEEK_END);

[Code] ....

(I want to read the whole file, its not that big)...

View 14 Replies View Related

C++ :: Store Contents Of Text File Into Char Array?

Apr 22, 2014

I am trying to store the contents of a text file into a char array. However the function i am using ifstream member function get(); seems to stop working when fed with certain characters. Is there another solution besides the get() function that will accept all types of characters from files?

char text[1000];
for (int i = 0; i <= textlen; ++i)
{
text[i] = text_in.get();
}

View 3 Replies View Related

C++ :: Large Int Anomalies In Exported 2D Array

Apr 9, 2013

My problem is my edit distance values are stored in a 2d array of ints and exported to a .csv and the ones at the end are rather LARGE.

The the edit distance max should be around 2000 but i am getting values of 1-100million, the weird thing is that I have checked back through my function and tested various parts of it and still dont understand where it is going wrong i thought it could be my memcpy and memmove parts but i have had no luck.

View 2 Replies View Related

C++ :: Reading Two Words Into Single Char Array From Text File

Sep 15, 2014

I am trying to read in player names (ex: first last) from a text file into the people[].name data struct. I can successfully read in my card file, but I cannot get this to work. I get a seg fault. I believe this is because nothing is actually being read in for my while loops. I can't use std::strings so these must be c-style strings aka char arrays.

// deck of cards
// below are initializations
#include <iostream>
#include <fstream>
#include <ctime>
#include <stdlib.h>
#include <string>

using namespace std;
//globals
const int maxCards = 52;

[Code] .....

View 1 Replies View Related

C++ :: Parsing Large Text File

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

C++ :: Getting Thumbnails (with Large Icons) Of Folder Not File

Nov 5, 2014

I am searching an API that can give me thumbnail(with large Icons) of all folders of all drive in Windows 7. Like

c:/--->Folder1,Folder2.....FolderN
d:/--->Folder1,Folder2.....FolderN
.
.
n:/--->Folder1,Folder2.....FolderN

How i can get associate thumbnail(with large Icons) of each folders of any of the drive.

View 5 Replies View Related

C++ :: Parsing A Large File Into Smaller Units

Dec 16, 2013

I have a large binary file (84GB) that needs to be broken down into smaller file sizes (~1GB to 8GB) for analysis. The binary file is on a 32-bit machine and cannot be copied to another machine for analysis. The PC has Visual Studio 6.0 and is not upgradable. My issue is I'm using the following generic code to create the smaller files.

fseek(file, start, SEEK_SET);
end = start + (variable based on file size);
fseek(file, end, SEEK_SET);
for (i=start; i<end; i++) {
if(!feof(f)) {
byte = fgetc(f);
fputc(byte,new_file);
}
}

However, on a 32-bit machine, the iterator can only count up to ~2billion. Which means that I'm unable to copy anything past ~2GB. My original idea was to delete from the large binary file as I read from it so that I can reset the iterator on every read. However, I haven't come across a way to delete binary file entries.

Is there any other way that to break down a large binary file into smaller units? Or is there a way to delete binary file entries in sections or per entry?

On a 64-bit machine I could use _fseeki64. I've been reading that some versions of Visual 6.0 are capable of supporting 64-bit numbers but when using _fseeki64 or _lseeki64 on this machine its an "undeclared identifier"

View 7 Replies View Related

C++ :: Dynamic Memory (array Of Char) - Delete All White Spaces In Text File

Feb 8, 2014

General Purpose: Delete all "white spaces" in text file, until the read-in char is _not_ a whitespace (mark as start of text file).

Problem: Cannot seem to shift char's over properly. (I think my problem is the inner loop - however other code may lead to this problem - I do not know)

Code:

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

bool trimWhiteSpace(fstream &file, char * charMemoryBlock) {
if (!file.is_open()) {

[Code] ....

View 3 Replies View Related

C++ :: How To Convert Large Valuge Form Single Integer To Array

Jun 3, 2013

i have mathematic operation and the result is near 70 digits....single variable cannot hold it....

View 4 Replies View Related

Visual C++ :: Program Creates A Large Pointer Array Of Numbers

Feb 22, 2013

I am working on a program which creates a large pointer array of numbers and then performs several iterations of operations in them.

Code:
int * u = new int[N];
double * nu = new double[N];
int * nud = new int[N];
for (int i=0;i<M;i++){
for (int i=0;i<N;i++){
u[i]=0;
nu[i]=0;

[Code]...

If M is small enough then there are no problems in the program. However once M is large enough I get the "unhanded exception":

std::bad_alloc at memory location 0x0026f728..

Since I am just reusing the same arrays, and since I am able to make it through a few iterations, I didn't think it could be a memory issue. If it is, is there a way I can clear the data completely after each iteration?

View 4 Replies View Related

C++ :: Getting A Large String Vector For File Content Manipulation?

Dec 10, 2013

I need a large string vector for file content manipulation.

v1.max_size() gives me 153 391 689.

But if I make a test by looping a vector pushing back strings it crashes around 16 - 26 000 000 though I still have a lot of ram (1GB left).

How come and why isn't vector size limited by ram instead?

View 11 Replies View Related

C :: Program To Show Large Text File In Parts

Jan 1, 2014

I am currently working out on a problem in which a c program is to be made which shows a large text file in parts.
f
For example: If file contains 200 lines. 50 lines will be shown on first page and user is asked to press any key to move to next page until EOF is found. user is allowed to return to previous page as well, and this is very complicated task for me. I tried to move cursor to a specific position using fseek etc but it page doesn't stop and reaches to end quickly.

View 1 Replies View Related

C :: Program That Takes A Large Text File As Input

Nov 7, 2014

I am writing a spell checker for a exercise for a class I am taking online. I have to load a huge text file of 143092 words into a hash table.

The program segfaults on word number 63197. Is there a way to debug this in gdb without having to step threw the function 63197 times.

View 3 Replies View Related

C/C++ :: How To Read And Store Large Amount Of Information From TXT File

Apr 1, 2015

Im trying to read and store several students information so that i can have an options menu where i can enter a student number and the program prints all the information stored about that student. The way i have it set up now, doesn't work for this because all info is reinitialized to stud1. Is there another way to store this info other than defining stud1, stud2,.....,stud200?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
struct student_info {
char first[20];
char last[20];

[Code]....

View 1 Replies View Related

C++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

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

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 Replies View Related

C++ :: Concatenate Two Char Arrays Into Single Char Array?

Sep 29, 2014

I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.

/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit

[Code]....

View 2 Replies View Related

C++ :: Read Text File Char By Char By Using Vector Class

Oct 29, 2014

Code:

cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())

[Code] .....

View 8 Replies View Related

C :: Char Array With A Phrase To Char Word

Nov 28, 2013

I need to do a function that copy every word from a text to a char word. How can i do it?

View 5 Replies View Related

C Sharp :: Finding String From Physical Memory Dump File (RAW File)?

Feb 5, 2014

I need to find a string(&login=) from physical memory dump file.And i have to print the word or string following it.Is there any C# code for this problem?

View 3 Replies View Related

C++ :: Finding A Value In 2D Array?

Jul 9, 2014

I want to search a 2D array to see if it contains a certain value x. I can come up with three different ways to do this. Provided I have:

const int Rows = 40;
const int Columns = 30;
int SampleData[Rows][Columns] = { ... }

Is there any real difference (in terms of performance etc.) between these, or are there an even better solution?

Solution 1:
for(unsigned row = 0; row < Rows; ++row) {
for(unsigned col = 0; col < Columns; ++col) {
if(SampleData[row][col] == x) {
// found
} } }

Solution 2:
int* data = &SampleData[0][0];
if(find(data, data + Rows * Columns, x) != data + Rows * Columns) {
// found
}

Solution 3:
int* data = &SampleData[0][0];
for(unsigned i = 0; i < Rows * Columns; ++i) {
if(*data++ == x) {
// found
} }

View 1 Replies View Related

C :: Array Finding Position Of A Value?

Dec 24, 2013

So for a project I'm working on, I'm using an array and generating it's values randomly but unique. Currently I'm working on a 3X3 array and the generated values are in the range from 1-9. So I wrote a function that will tell me the position of the cell whose value is 9. This is the function I wrote:

Code: void Llogaritje1(int t[3][3],int &i, int &j){
int y,l;
for(y=0;y<3;y++){
for(l=0;l<3;l++){
if(t[y][l]==9){
i=y;
j=l;
break;
}
}if(t[y][l]==9) break;
}
}

But it doesn't work on all cells. Seems like at cells t[1][0] and t[2][0] the values that i and j take are 0 0 since when I print them after excecuting the function that's what it returns. I really don't understand why.

View 4 Replies View Related

C :: Finding The Minimum Value Of Array

Sep 9, 2013

I am trying to make my program read a bunch of numbers in an array to find its maximum and minimum. the program will ask the user to enter in as much number as possible until they enter a non number/letter. i got my program to find the maximum value but the program couldn't read the minimum value. it always says zero. also everytime i enter the number 0, the program will just finish its loop statement. If i typed in a negative number, it'll read the negative number as its minimum.

Code:
#include <stdio.h>
int main()
{
//-------variables------------------
double list[1000]; // can hold 1000 items
int i;
char letter;
int max = list[0];
int min = list[0];

[Code] ....

View 5 Replies View Related

C :: Finding Diagonals Of Array?

Apr 11, 2014

Most of this program is working correctly, however when I get to the part on lines 70 to 78 to try and use the function on lines 103 to 113 to find out each diagonals value and then print each one back. But when this runs it only returns the value for [0][0] for each run through the loop and I'm not really sure why. I know its probably something simple but I'm just missing it,

Code:
1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<time.h>
4 #define MAX 100
5
6 void display_menu();
7 int check_option(int);

[Code]...

View 4 Replies View Related







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