I am attempting to read a ppm file. When i do it i try to write it back in another file just to see how's done and i get a terrible result. I assume the problem is something with the casting i do to the variables.
This is my image class
Image:: Image(unsigned int width, unsigned int height, bool interleaved) {
buffer = new Component [3*width*height];
this->height=height;
this->width=width;
this->buffer=Component();
I'm writing a program using Huffman algorithm to compress text file. I have tested my program by just printing the printing ASCII character to file and it worked fine. However, now I have to implement using bits and my program doesn't work. It seems like I'm not reading or writing the right bits. Here is the result of my testing:In the input file I put abc the input file to compress it. Then I uncompress it the out out is aaa. Below is a snippet of how I read and write bits
Code: class BitInput { istream& in; // the istream to delegate to char buf; // the buffer of bits int nbits; public:
I have a text file containing 500 signed decimal numbers. My task is to read each entry and convert into a 16-bit 2's complement representation (binary number) and write into the another text file.
Is there a way to read and write to the same file?
I'm writing a game program and I want to save the score at the end of the game to a txt file. The txt file already contains other game scores. How do I store the score without overwriting the previous scores.
I'm writing a program using Huffman algorithm to compress text file. I have tested my program by just printing the printing ASCII character to file and it worked fine. However, now I have to implement using bits and my program doesn't work. It seems like I'm not reading or writing the right bits. Here is the result of my testing:In the input file I put abc the input file to compress it. Then I uncompress it the out out is aaa. Below is a snippet of how I read and write bits
public:
BitInputStream(istream& s) : in(s), buf(0), bufi(8) { } /** Read the next bit from the bit buffer. * Return the bit read as the least significant bit of an int. */ int readBit(){ int i; if(nbits == 8){ buf = in.get();
I have a jpg file. I have extracted the width and the length of the image. I have done that with some codes and markers. Now I need the image data starts as from that place i would like read the data and print the pixel value. I would like to display the pixels later.
I have a file of data where each line consists of 4 parameters (degree, alpha, beta and x) and a value corresponding to these, organized in increasing order of the parameters. Here's the test file I'm using:
My code is supposed to look for a certain set of parameters (currently set to 1 2 1 1.5, which is not contained in the file) and its value. If it's there (i.e. the file contains the value for the right parameters) the program is done. If not it should calculate the value using a function JacobiPoly() and insert the wanted parameters and corresponding value in the appropriate place in the file.
I have a code in which I think everything works except the writing to file. I use an fstream so I can both read and write and open it with ios::out||ios::in. I'm also aware I need something similar to fseek in between input and output but according to [URL] .... reading and writing to the same file using the same fstream, seekp() should suffice. I'm using seekp(), but the output (in the form inout << (...)) doesn't work.
I am having problems either writing data to a binary file or reading from the file. Through the process of elimination I am posting the code where the data is written to file to see if I can eliminate that as an option. I know the data is being processed correctly because, through the use of another function, I can view the data.
I also know that fwrite must be including some padding because the file size ends up being 576 bytes after it is written instead of 540 bytes (the size it would be if no padding is used). Here is my struct:
Code:
typedef struct { char teams[25]; float wins; float losses; float pct; int runsScored; int runsAgainst; } STATISTICS;
Code to write data(Double type e.g 12345.67891) in text file like pattern given below. Remember to put tab between each column.
----------------------------------------------------- Column1 Column2 Column3 Value 1 Value 2 Value 3 Value 4 Value 5 Value 6 Value 7 Value 8 Value 9 ----------------------------------------------------
I'm currently working on a server for handling clients in a 2d online game and I wrote some regular fstream file code for handling the file that stores their information and I was about to implement it into the server, then I realized there might be a problem having it open multiple times concurrently, so I googled it and came up with posts like
[URL]
I'm wondering if I can just treat it like everything else or will I have to do something specific for opening on multiple threads?
p.s. I did read those posts but I'm very new to multithreading
I'm having issues with writing to a file. more precisely, i'm trying to determine if a set of numbers are in the file. if they are already in it, don't write to the file. if not, write to the file. My problem is my program is writing all numbers, even duplicates. The sort is working.
#include <iostream> #include <fstream> #include <algorithm> using namespace std; //Counter Stats int STR;
I have this image/video compression project that is to be done in C. I've been given this source code by my supervisor which is supposed to be a working one.
Assuming I have a sequence of 5 images in .pgm format (image41.pgm, image42.pgm .... image45.pgm). Some of the code involved is
When I tried to compile the code using make file (shell script), I got this error message "In function 'readPgm' format '%d' expects argument of type 'int *', but argument 3 has type 'unsigned char *' "
Can identify what the problem is and how to rectify it?
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 ....
Basically, I want to write an image to disk in parallel with an algorithm that is processing that same image. The code is really simple:
Code: string ProcessImage(System::Drawing::Bitmap ^bmp, System::String^ targetFile) { bmp->Save(targetFile); System::Drawing::Bitmap^ bmp8 = BitmapConvertPixelFormat(bmp, 8); //<-- a function I wrote which converts the 32bpp I am passed into an 8bpp one string results = Analyze(bmp8); //<--- takes a good bit of time return results; }
What would be the fastest way to do this? Any libraries with a code sample. I would prefer one that is within .NET or native C++ just to avoid having to link into many different libraries.
I have an assignment where I need to take an assigned image, rotate it 90 degrees to the right, flip it upside down, and turn it to grayscale; each with different outputs.
I was thinking if I can read in the image into a 2d array //array[height][width] or even just an array with the values of each pixel (r, g, b), I can just modify the array and spit it out when done.
if i can just get it into the array, I think I'll be fine. We've done similar assignments with modifying arrays for grayscale images and the other two I can probably figure out. But how am I going to read in each pixel into an array with three different values in each slot? This is my code so far:
Name: Mary Smith Exam 1: 65 Exam 2: 79.1234 Exam 3: 70.24
Becomes something like this in the output file:
Name: Parker, Peter Average Score: 92.28 Grade: A
Name: Smith, Mary Average Score: 71.45 Grade: C
I know I'm supposed to read the whole file, but I'm getting really confused on how to take the name of each student separately without recording Exam 1, 2, and 3. I'll be able to do the average score and grade on my own.
I have to make a program that asks for your username (any)to register it. When you type it it will say something. I want to create a txt file also. so this is what I have:
#include <iostream> #include <fstream> using namespace std; int main() { int a; { ofstream myfile;
[Code] ....
now, how can I use the cout again to print something "Welcome to the program..."?
I'm messing around with reading and writing files. The first file creates a small txt file. Simple enough
#include <iostream> #include <fstream> #include <string> using namespace std; int main(){ string name; string desc;
[Code] ....
It does what it should. It creates a text file "items.txt" .... It reads as such:
dagger,a dagger,15,10,0,1,3,1,0,0,0,1,0,0,0,0,0,1
The second file is meant to read the file and place the data back into the variables. This happens, but the data crams itself into the first variable, and the rest of them collect the trash that's in memory.
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { string name,desc;
[Code ....
I need to get "dagger" into name, "a dagger" into description, and each value with their perspective variable. I'm sure I need some type of "separator". Hopefully I can use the comma. Before it's over, I will have about a hundred items that will need to be read into a class of items.
I'm trying to read a PPM image into an array. The header will have already been read in and I'm trying to put in a 2-d array to make manipulations easier. This is the code I have so far with LOTS of errors and warnings and I honestly don't know what almost any of them mean.
Code:
int imageArray( FILE *input, struct pixel *theArray ){ int i, j; int col, row; int *imageArray = (int**)malloc(row * sizeof(int*)); for(i=0; i<row; i++){
program that I am working on. I want to use fgets() in my program so I could handle multiple words from a text(to be able to handle spaces). I get a weird result when running the program.
How to write the code for this with the following requirements:
download the text file weblog.txt
This file is an Apache web log taken from the web server for St. Mary's University. When a visitor goes to their web site, the visitor's browser makes a request to the web server to view a web page, which is a file residing on the server. Each time a page is requested by a browser, the web server records information about that request. This weblog.txt holds the details of some of those requests.
Create a non-member function to read each line of the web log file. This function must do error checking to ensure that the file is opened successfully, otherwise it must provide a message like "file not available" to the user.
Each line should then be stored in a vector such that the first element of the vector is the first line of the web log file. Because each element will hold an entire line from the file, the vector should be declared as a vector of strings.
Note: You must declare the vector in a function.
Create another non-member function to sort the contents of the vector. Make sure to pass the vector by reference or your sort will disappear when the function ends! Use the sort function with #include <algorithm> to do the sort; you do not have to write your own sort algorithm.
Create one more non-member function to write the contents of the vector to a file. Each element should be on its own line in the new file. The contents of the new file should look like the original input file once your program completes, but in sorted order.
Create a main function that calls all of your non-member functions.