C/C++ :: Read A Raw File And Convert It To 8 Bit

Feb 19, 2014

I am trying to rewrite a matlab code into c++. It reads a file and do the deresolution on it and convert it to 8 bit.

but the VC++ code does not work for all ranges of max_den and min_den. Specially when the there is a small difference between them. (I tried that range on Matlab, it works)

MATLAB Code:

fid = fopen(ORIGINAL_FILENAME,'r');
A = fread(fid,X*Y*Z,'int32=>int32')
D = uint8(255/double(Maximum_Density-Minimum_Density)*(A-Minimum_Density));
A = reshape(D,X,Y,Z);
fid=fopen(OUTPUT_FILENAME,'w');

[code].....

For example when actual range of data is [-3023,3072] and the max_den=-3000, min_den=1000, it works well. but when you choose max_den=-1000, min den=1000, it doesn't work properly.The raw file includes 3D data associated with a mhd file. When the range is not wide enough, the converted file becomes messy.

View 1 Replies


ADVERTISEMENT

C++ :: Read In String From File And Convert It Into Enum?

Dec 2, 2013

I defined

enum boundaryType_t {inside, inlet, outlet, wall, periodic};

now I have file written like this:

inside outlet

I want my program read the file and when encounter any enum type, instead of treating it as a string, I want the program store it in memory as a enum value.

How can I do that?

string s;
ifs>>s;
s // how to convert it to enum???

View 5 Replies View Related

C++ :: Not Able To Read Data From Text File And Convert It To Integer

Mar 25, 2013

I am trying to read an array values from Tmin.txt file. I take array size from user viz. number of raw & column and then, read the following data from Tmin.txt file which look like this:

20 40 20 25 30

20 30 40 20 25

20 40 20 25 30

20 30 40 20 25

30 40 40 30 40

I am using getline, and then converting it to int by using atoi. But my code is not working.

Code :
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code] ....

View 10 Replies View Related

C# :: Convert Dictionaries To Arrays To Read And Write Sequentially

Nov 27, 2011

Code:

// declare child arrays
public string[,] childcolor;
public string[,] childgeneo;
// create dictionaries
public Dictionary<string, int> colors = new Dictionary<string, int>();
public string color; // name for dictionary
public Dictionary<string, string> geneo = new Dictionary<string, string>();

[Code]...

I'm getting "field' is used like a 'type' error on jw.childcolor which causes other parts to error out.

How do I fix this & why am I getting the error?

I want to convert the dictionaries to arrays to read & write sequentially.

View 4 Replies View Related

C++ :: Getline And Atof - Convert Read Value Into Floating Number

Aug 3, 2012

Having an issue with the following code. I read in a decimal value from a text file, use atof (or strtod, either gives the same error) to convert the read value into a floating point number. When putting the output of atof in a double, it works fine. However when putting the output of atof into a float, the decimal places get lost. Putting the result in a double, then into a float gives the same result. This only happens when using getline.

I've tried using temp arrays to put the result of pch in, sprintfs and such to try and work around it, but whenever a value originates from the getline command, the float value always loses decimal places. I've also tried varying the precision in the printf statement, but its always the same. When I write the float result to a file via FILE.write in binary mode, the result comes out without the decimal places when I read it back in later.

The simple solution is to not use float and use double, but there are a number of reasons I'm using float to begin with and don't want to change that.

Side note, this code works fine on a windows machine, the error is coming from using g++ on a mac.

Code:
printf("Reading from File
");
ifstream FILE(argv[2],ios::in);
char BU[128];
char *pch;

[Code] ....

Code output :

Reading from File
338769.0109
338769.010900
338769.000000

View 4 Replies View Related

C :: Read Contents Of A File Using Low I/O Read Statements

May 15, 2013

I want to read the contents of a file block (512 bytes) by block using low I/O read statements. Each record is 64 bytes long and has a pre-defined structure. The first 4 bytes are an unsigned integer; the next 20 bytes are ascii text, etc.

I have a buffer which I can access with buf[0] to buf[63] to read the first record and then buf[64] to buf[127] for the second, etc. However, I was wondering how to map a record so that I can refer to an integer as an integer and a float as float, etc. I can't create a struct and move the 64 bytes to it, as I will have alllignment/padding problems.

What is the standard way to deal with records in C?

View 5 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C :: Convert List Of Names From One Text File To Email Format In New File

Jan 19, 2014

I have almost a hundred names in a text file that I want to convert to email addresses and save to another file. I seem to have it working, but it doesn't print the full names in the email prefix. The output I'm looking for is Doe_John@livebrandm, but I'm only getting D_J@livebrandm. I'm not sure what I should specifically be reading up on that applies to this directly.

Code:

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fpin=fopen("namesIN.txt", "r");
FILE *fpout=fopen("emailOUT.txt", "a");
char first[20],last[20],inbuff[1500];

[Code]...

View 9 Replies View Related

C++ :: Convert Text File Containing 0 And 1 To Binary File

Apr 15, 2014

I just wrote a program for Huffman Encoding, where I take a text file, encode it in the form of 0's and 1's, and save that as another text file. However, this does not solve my purpose as it is taking even more space.

So I want to know how do I convert a text file containing these 0'S & 1's to a binary format.

Here is my program:

#include <stdio.h>
#include <string.h>
#include<fstream>
#include<string>
#include<iostream>
using namespace std;
typedef struct node_t {
struct node_t *left, *right;
int freq;
char c;

[Code]...

View 1 Replies View Related

C :: Convert DAT File Into TXT

May 19, 2014

I have written this to convert this .dat file into .txt file but it is not working well. It create one .txt file and also with content but contain some garbage content also .

Code:

#include <stdio.h>
#include <stdlib.h>
void fileInput(cfPtr);
void convertText(cfptr);
int menu();
}

[code]....

View 1 Replies View Related

C++ :: Convert PDF To TIFF File

May 15, 2013

I am developing a program that convert PDF files to TIFF files. I use imagemagick++ and can accomplish the concersion successfully. But the resolution of the multi-page TIFF files is too low. My code follows:

vector<Image> imageList;
for(int i = 0; i < imageList.size(); i++) {
imageList[i].resolutionUnits(PixelsPerInchResolution);
imageList[i].density("300");
}
readImages( &imageList, "E:/gk11.pdf" );
writeImages( imageList.begin(), imageList.end(), "D:/gk11.tif" );

Although I change the density in the code, but it seems don't work.

View 7 Replies View Related

C/C++ :: Convert File Name Into A String?

Feb 18, 2014

there is a way to convert a file's name into a string.

Sample:

filename = testcode.txt

it will convert the file's name into a string:

char convert[100];

covert = name of file

Is this possible?

View 3 Replies View Related

C :: Create File To Write Text And Read Back The File Content

Mar 15, 2013

The Objective Of This Program Is To Create A File To Write Text And Read Back The File Content. To Do That I Have Made Two Function writeFile() To Write And readFile() To Read.The readFile() function works just fine but writeFile() doesn't.

How writeFile() function Works? when writeFile() function Execute It Takes Characters User Type And When Hit Enter(ASC|| 10) It Ask "More?(Y/N)" That Means What User Want? Want To Go Next Line Or End Input?

If "Y" Than Inputs Are Taken From Next Line Else Input Ends.

But The Problem Is When Program Encounters ch==10 It Shows "More?(Y/N)" And Takes Input In cmd variable.If cmd=='Y' I Mean More From Next Line Than It Should Execute Scanf Again To Take ch I Mean User Input.But Its Not!!! Its Always Showing "More?(Y/N)" Again And Again Like A Loop.

Code:
#include <stdio.h>
void writeFile(void);
void readFile(void);
int main(){

[Code].....

View 5 Replies View Related

C :: Writing A Simple File / Text Parser To Read A Config File

Feb 6, 2014

I am writing a simple file/text parser to read a config file for some code I am working on. It's dead simple and not particularly smart but it should get the job done. The code reads a config file:

Code:

readlength=2500000
start=0
finish=25000000
cutoff=20000
samplingfreq=250000
poles=10
filterpadding=500
}

[code]....

Here is where it gets wierd. You'll notice that there is an unused variable (filepath) in the config struct. This variable is not referenced or used anywhere in the code, ever. Yet if I comment out the declaration of char filepath[1024], the code segfaults partway through the read_config() function.

My best guess is that there is a buffer overflow elsewhere and it just so happens that the memory allocated for filepath happened to be there to catch it up until now, but I can't work out where it might be happening. With the declaration commented out, the read_config() function gets as far as reading the "padding" variable before it crashes. Yet when the declaration is there, then all the variabled are read correctly and everything seems to work.

View 10 Replies View Related

C++ :: How To Convert CPP Files Into Injectable DLL File

May 26, 2014

My IDE is eclipse, but the way I set it up it's unstable. Is there a way to do it without an IDE?

View 2 Replies View Related

C/C++ :: Convert TXT File To Bin And Vise Versa

Feb 15, 2014

I am having a problem with converting a .txt file into a .bin file. It wokrs but only creating a new file and not being able to actually convert it, i have to do this using the fstream functions. I have already created the files in the project file e.g if i type file . file.txt is in the folder.

Here is my Binconvert function -

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
fstream fMyFile;
char Name[256];
char Words[256];
char txtextension[] = ".txt";
char binextension[] = ".bin";

[Code] ....

View 9 Replies View Related

C++ :: Convert Int To Const Char (for A File Name)

Jan 20, 2014

i found a lot about how to convert int to const char * but non of them explain correctly or sometimes dont even work.

Here is my code:

#include <stdio.h>
#include <cstdlib>
using namespace std;
int main () {
int i =0;
char c1 =0;
char c2 =0;

[code]....

View 15 Replies View Related

C/C++ :: Convert Video To Audio File?

Jan 23, 2014

I making a application which convert video to audio in MFC. i want make it without using FFMPEG . How can it possible.

View 1 Replies View Related

C :: How To Read Data In A File And Print It Then Copy Contents To A File

Mar 8, 2013

Code:

#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
char buffer[256];
FILE * myfile;
myfile = fopen("read.txt","r");

[Code]...

I also got an error in printing wherein the data in read.txt is "Hello" newline "World" and my program prints world twice.

View 3 Replies View Related

C++ :: Read From A Txt File And Then Write A New Text File With Sorted Line

Jun 11, 2014

I have a .txt file which I want to read from and then write a new text file, this time with sorted lines. It is easy to sort one value, but what about sorting entire lines based on one value?

I want to sort the lines based on the FIRST value.

Example text file contents:

values;data
5.01 100
2.9 342
2.69 43534
10.1 43
6.8 45324

Output: Text file containing

2.69 43534
2.9 342
5.01 100
6.8 45324
10.1 43

It's easy to do this if there was only 1 number on each line, but I do I sort all the lines based on the first number in each line?

View 2 Replies View Related

C++ :: Read Input File (XML) And Generate Output File

Mar 25, 2013

I have code that reads an input file and generates an output file .For reading the input file we have a xml file.If there is an error while reading or writing the output file the an errored file is generated. But in the errrored file the fields are not coming as in accordance with the reader xml . They are coming randomly . In the module for reading and writing the errored file list is being used . What should be done to write in the errored file as the reader xml fields.

View 1 Replies View Related

C++ :: File Handling - Program To Read Inputs In TXT File

Mar 26, 2013

I've written a program to read inputs in a text file. The file named Input.txt contain integers 2 3 and 4. My program is as follows:

#include<iostream>
#include<cstdlib>
#include<fstream>
using namespace std;
int main (){
int x,y,z;

[Code] ....

the program is outputing x=2293616 , y=0 and z=0 instead of x=2, y=3 and z=4.

View 9 Replies View Related

C++ :: File Read / Find - Miss 1st Line In File

May 3, 2013

I wrote the below code to find the line with "abc" as my parameter to strTosearch. I expected to the line 1st line but, this function always match the 2nd line. What am I missing here?

I wanted "found" to be "abc def hgi SSS".

Code in main()
String found=GetstringColSamLine("mytext.txt", "abc");

File name - mytext.txt
abc def hgi SSS
abc ppp yyy
string GetstringColSamLine(string routerFileName, string strTosearch)

[Code] ....

View 3 Replies View Related

C++ :: Read From Txt File One Bit At A Time And Then Write Into Binary File

Apr 22, 2013

I am trying to get the code to read from the txt file one bite at a time and then write this bite into the binary file but i cant seem to get it working.

FILE *fpcust, *fpcustbin; //<<<<<-----point to both sales and customers text files, and the new .bin files for both
char buffer;
int ch;
int ch1;
fpcust = fopen("c:customers.txt", "r"); //<<<<-----pointing to the file
fpcustbin = fopen("c:customers.bin", "wb"); //<<<<<-----pointing to the new binary file, opening in writing binary

[Code]...

View 3 Replies View Related

C++ :: How To Save Struct To File And Then Read It Back From The File

Aug 5, 2013

How to save the struct to file and then read it back from the file ?

Code:
#include <conio.h>
#include <stdio.h>
struct student {
int person;
int egn;
float AvergeGrade;

[Code] ....

Have average grade: %f", person[i].FirstName, person[i].LastName, person[i].egn, person[i].AvergeGrade);
}
//Save to file
getch ();
}

View 2 Replies View Related

C++ :: Read Input File (XML) And Generate Output File

Mar 25, 2013

I have code that reads an input file and generates an output file .For reading the input file we have a xml file.If there is an error while reading or writing the output file the an errored file is generated. But in the errrored file the fields are not coming as in accordance with the reader xml .they are coming randomly . In the module for reading and writing the errored file list is being used . What should be done to write in the errored file as the reader xml fields.

View 1 Replies View Related







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