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


ADVERTISEMENT

C++ :: Reading Strings From File To 2D Array?

Apr 27, 2013

I have a text file with scores and names.

I have to read the score into an array and the names into an arrays also

27,Tom Jefferson
23,Ozzie Osborne
18,Wilt Chamberlain
15,Marie Antoinette

I've gotten the score to display correctly, but i cant get the full names. My function only reads the first names

View 8 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++ :: 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 :: Remove Duplicate Strings From Char Array

Apr 15, 2014

The goal is to merge two files of names, sort them and remove duplicates.I've managed to merge the two files into a single char array and sort them with a function so they are alphabetical.I'm having problems removing the duplicate entries from the array. Here is my code:

Code:

#include <stdio.h>
#include <string.h>
#define NUMSTR 10
#define STRLNG 9

[Code]....

View 3 Replies View Related

C++ :: How To Insert Strings Into Array Of Type Char

Sep 2, 2013

How to insert strings into an array of type char and also delete strings from that char array.

View 4 Replies View Related

C++ :: Enter Multiple Strings Into Char Array

Feb 16, 2014

I am having issues getting this working. This is a simple program that is designed to ask a user if he would like to enter a string, if yes, the user is prompted to enter it and its stored in a char array. User is then asked if he wants to enter another string... Once user responds no, the program outputs the strings and the program ends...

Note: I'm using in.getline(myarray[i], MAX, ' '), to avoid white space problems if user enters a space. Lastly I would like the option of letting user enter any number of strings, but how would you do this when declaring the 2 dimensional char array?

#include <iostream>
#include <string>
using namespace std;
const int MAX = 81; //max char is sting is 80
int main(){
string y_n;
bool go = true;

[Code] ....

View 2 Replies View Related

C :: Reading Strings From File

Nov 2, 2013

It appears that when you enter command line arguments or use fgets() to input a string you can assign that string to another string variable using the assignment operator. But when you read from a file, you can't do that, you get a segfault. It seems the only way to get around that is to malloc the string and use the strcpy function.

Code:
#include <stdio.h>
struct person {
char *names[2];
};
void readFile(struct person p){
FILE *file = fopen("names", "r");

[Code]....

View 3 Replies View Related

C++ :: Reading Strings From A File With Spaces?

Aug 2, 2013

I need to write a program that reads a paragraph from a file (i dont know its length) and i need to read it with spaces

i thought of using getline() function but there were problems:

1) how to detect End Of File

2) how to use getline while reading from file

and thought of reading one character at a time but it didnt read spaces

View 4 Replies View Related

C++ :: Reading Series Of Strings Into Array Then Output

Feb 24, 2015

The requirement was to set the txt files information equal to a variable before and not to put it directly into the array.

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
const int MAX = 24;
struct applicant_info {

[Code] .....

the txt doc looks something like this: file name: jobs4.txt

View 2 Replies View Related

C :: Reading Formatted Strings From Text File

Nov 28, 2014

I wanted to improve the game from my last thread. I want to read and store a question in this format: Code: Who invented the BALLPOINT PEN?

A - Biro Brothers
B - Waterman Brothers
C - Bicc Brothers
D - Write Bothers

But when I use fgets() to read the string, it reads all the ' ' literally instead of outputting a real newline. Like if it read the above question, I want it to print something like this:

Code:
Who invented the BALLPOINT PEN?

A - Biro Brothers
B - Waterman Brothers
C - Bicc Brothers
D - Write Bothers

View 3 Replies View Related

C :: Reading Matching Strings From A File And Deleting From Another

Sep 26, 2014

We are generating emails for freshman students, however, the system probably due to server overload fails to generate some emails. So I'm working on this c code( probably was a wrong choice) to search for regexp matching the generated emails and deleting from the list of students and propective emails.

I"m currently at the stage of making sure the code can find all the matching regexp from the student list file before deleting! But the code fails to read all matching regexp?

Code:
//Filename: SearchReplace.c
//Usage: This searches for lines in a file containing a particular work and deletes the lines.
//Licence: GNU P.L.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

[code] .....

What I'm missing. It recognizes some regexp and fails to recognise some. Been staring for hours!

View 4 Replies View Related

C/C++ :: Reading Strings From A Text File And Printing Them

Feb 26, 2015

I need a program that reads the number of lines of a file and then several (max of 20) lines of text from a .txt file so an example of the .txt file is: 2 This is the first string This is string number 2 So it first reads the 2 and then reads the two lines of text. It stores the text in an array of pointers. The code i have so far is:

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>

[Code].....

It doesnt give me any errors but all it does is keep running and doesnt print anything out kind of like its in an infinite loop although i dont see how that could be possible.

View 1 Replies View Related

C/C++ :: Reading Strings From A File And Determining If They Are Palindromes

Oct 17, 2014

I have to make a program to read a file with strings and determine if they are palindromes. The problem is that the program says that they're all palindromes.

int main() {
ifstream inFile;
ofstream outFile;
inFile.open("in.data");
outFile.open("out.data");
if (!inFile || !outFile) //to display error if input files are invalid

[code]....

View 3 Replies View Related

C :: Visual Studio 2012 - Writing Data Into TXT File / How To Stop Reading Char

Feb 23, 2013

I am using visual studio 2012.....in below code i m writing data in to a test.txt file but i dont know with which key file stop accepting char...i tried ctrl+z and ctrl+d but not working ....

Code:
#include<stdio.h>
#include<conio.h>
main(){
char ch;
FILE *ptr;

[Code] ....

View 7 Replies View Related

C :: Combinations - Putting Strings Into Array From A File

Apr 4, 2014

The first line of my input file is going to contain some number "T" which will represent the "combination length" of a list of random words. (In this case, they are Taco Bell items). The first number on the second line represents the number of unique items on the menu to get, and the second number on the second line represents the number of unique items that are supposed to be bought.

Basically the input will look like this: 2 3 2 taco burrito nacho

And the output looks like this: burritos nachos nacho taco burrito taco

This is what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main(void){
int N, T, K;
char menu[N][20];

[Code] .....

What I am trying to get working right now is just to scan a file and put the strings into an array so then I can work on sorting the array. How can I add strings from a file into an array?

View 4 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++ :: How To Copy Strings From File Into Array Of Pointers

Jan 13, 2014

I am trying to copy string Line BY Line from text file into array of pointers. lets say file has only two lines for example.

This is an apple.
This is another apple.

I want to copy both of these lines from file to array of pointers. Below is the code which i am trying to use for this.

Code:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <string.h>
using namespace std;
int main() {
char const *filePath = "test.txt";

[Code] ....

View 14 Replies View Related

C :: How To Make String Array From Strings In Text File

Mar 24, 2013

I want to make a string array from strings in a text file. Itry to do this but i couldn't do, where is my mistake?

Code:

#include <stdio.h>
#include <stdlib.h>
int main(){
char cumle[100],*c,*dene[50];
FILE *input;
input=fopen("input.txt","r");

[Code]...

View 1 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

C++ :: Can't Compare Char Strings

Jun 13, 2013

I have two char* that have the same data in (hypothetically).

std::vector<char*> Buff;
Buff = Split(Line, '.');
char* A = "data", B;
B = Buff.at(0)

Where Split is a function that I made to split a string (Line in this case) into a char* vector, this string contains a line from a file. Line is char* too. The weird problem is when Buff data stored in its 0 position is given to B... because B is equal to A (hypothetically) but when this is compared to do certain functions they doesn't match!

Here an example:

std::vector<char*> Buff;
Buff = Split(Line, '.');
char* A = "map", B;
B = Buff.at(0) // Buff.at(0) should be "map" and is apparently "map"

[Code].....

NOTE: I didn't use switch to compare Cmd because I want it separately for easier debugging.

Is there something wrong with my codes?? or what happened here with those hex values before the string in my variables?

View 6 Replies View Related

C++ :: Trimming Char Strings?

Jan 12, 2015

I have created a char string[100]. I know this array will be big enough for its purpose. The problem is that it often too big. When I print this string array I get the text plus a lot of gobbledygook at the end which I assume is the extra memory at end of string array. How would I approach trimming this using just C.

I suppose I could nest a for loop that adds to a new array that has a size determined by a counter(although this would give a warning being that a VAR is determining size of array) but I suppose there is a much simpler way to do this.

View 2 Replies View Related

Visual C++ :: Reading Into Array / 2d Array From Mixed Text File?

Jan 18, 2014

I know to read a strings into array and tables.. what is they are mixed up?? strings are just names ( 3 characters) and there are bunch of table.. the max size was set to 60

ex. text file

JES
DAN
JEN
.
.
.
01010101
10010101
RAM
JET
01010010
10100101
.... and so on

should i use a while loop?

View 10 Replies View Related

C++ :: Compare 2 Dates From Strings / Char Or Int

Mar 16, 2014

i have been trying to compare a date format from SYSTEMTIME and a date from a text file(string).But its not working. I tried to change both to string(using osstringstream),char* and int(using sscanf) to do the comparison but with no luck. its pretty simple all i want to do is get the current system date and compare it with the date from the text file. Below is my code:

char szcurrentDate[MAX_PATH] = "";
char szdate_time[MAX_PATH];
SYSTEMTIME st;
GetLocalTime (&st);
GetDateFormat(LOCALE_USER_DEFAULT,NULL,&st,"yyyy-M-d ",szcurrentDate,MAX_PATH); //current system date
//std::ostringstream mm;

[code].....

note : i tried displaying just szcurrentDate and szdate_time they show the date exactly the same. in string,char* or int formats.

View 2 Replies View Related

C :: Writing Array Into File And Reading Array From File

Apr 20, 2014

i've been trying to write array into file and read them into the same program again, but the output is all wrong.

Code:

#include<stdio.h>
int main()
{
FILE *fp;
char name[3][7];
int x;
}

[code]....

View 1 Replies View Related

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 View Related







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