C :: Fread / Fwrite And Fseek (reverse Of WAV File)
Jun 28, 2013
I am trying to write a function to reverse a wav file. The idea is to copy the header as it is from the begening of the input.wav file to the beginning of the output.wav file. After that i have to take count number of bytes(count = numberChannels * bitsPerSample in the wav i use this is 2*16= 32 bits, 32/8 = 4 bytes). With this code i am trying to copy the header( that's working fine) and then copy 10 samples from the end and put them to the output.wav file(after header not at the beginning).
This is the content of the input file:
The last 4 bytes of the header are bolded.
Code:
52 49 46 46 24 bd 01 00 57 41 56 45 66 6d 74 20
10 00 00 00 01 00 02 00 44 ac 00 00 10 b1 02 00
04 00 10 00 64 61 74 61 00 bd 01 00 00 10 00 10
ff 00 10 00 00 10 00 10 00 00 ff 10 10 10 00 10
00 00 00 10 10 10 10 00 00 00 10 00 10 00 10 ff
00 10 00 00 10 00 ff 00
This is the content of the output file it suppose to have in my example
Code:
52 49 46 46 24 bd 01 00 57 41 56 45 66 6d 74 20
10 00 00 00 01 00 02 00 44 ac 00 00 10 b1 02 00
04 00 10 00 64 61 74 61 00 bd 01 00 10 00 ff 00
00 10 00 00 10 00 10 ff 00 00 10 00 10 10 10 00
00 00 00 10 10 10 00 10 00 00 ff 10 00 10 00 10
ff 00 10 00
Code:
void reverse(char **array) {
int i=0;
word numberChannels;//word is unsigned short int , byte is unsigned char
word bitsPerSample;
[Code] .....
The problem is that (having in mind per sample is 4 bytes) instead of copying 40 bytes it just copies 20
View 1 Replies
ADVERTISEMENT
Jan 21, 2015
I try to crypt file with XOR instruction, by always receive segmentation fault. What's wrong with it?
Code:
#include <stdio.h>
main() {
FILE *fin,*fout;
char buff[40];
int a=0x11;
int i=0;
[Code] ....
View 4 Replies
View Related
Jul 20, 2014
I'm currently working on a program that writes an array of struct to a file and then read back the data from the file to another array of struct. At the bottom is an image of my result.
My goal is to end up with two identical struct arrays but my program fails to do this. My struct have to members: ID and kind (of animals in this case). I declare my first arraystruct africa[] with "monkey" and "giraffe" with their respectively IDnr: 112 and 555. I stream this data to a file and read read them back to the arraystruct get_animal[]. Simply I want the get_animal[] to be identical with the africa[] when the program is over, but that is not so. According to my result(bottom image) it display:
112, monkey (get_animal[0])
112, monkey (get_animal[1])
meaning that get_animal[0] is identical to africa[0] get_animal[1] is also identical to africa[0]
but why? I want get_animal[1] to be identical with africa[1]. meaning I want the result to look like this:
112, monkey
555, giraffe
I've also made the program to print the parameters of my fwrite/fread calls. Why is the 3rd parameter = 1 meaning that only 1 element will be read/written when my program just read/write 2 elements?
Code:
main(){
FILE *fp;
struct animals
{
int id;
char kind[20];
} africa[1] = {{112,"monkey"}, {555,"giraffe"}};
}
[code]....
View 3 Replies
View Related
Oct 28, 2014
I am trying to write my files to another subfolder . Below is my program.
Code:
cat th6.c
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#define SIZE 8
#define NUMELM 8
[Code] ....
I observe my filename along with directory as text in the new file created in sublfolder. This is output.
[cporgs/apue/threads]: mkdir first
[cporgs/apue/threads]: ./a.out test.txt first
test.txt -- first/test.txt
dfdfdfdfdfdfdf-14
dfdfdfdfdfdfdf-14
in thread test.txt first
[cporgs/apue/threads]: cat first/test.txt
dfdfdfdfdfdfdffirst/test.txt
[cporgs/apue/threads]: cat test.txt
dfdfdfdfdfdfdf
I could not able to get from where this filename and folder is getting added.
View 4 Replies
View Related
Feb 9, 2015
i wrote a little program with fseek. It works good till it reaches the first fseek(). Then it crashes and stops responding.My code:
ifstream inp("myfile.txt");
if(!inp.is_open()) return false;
inp.close();
FILE *f;
fopen("myfile.txt","rb");
[code].....
View 2 Replies
View Related
Oct 16, 2013
I am currently reading several values one after another from a file like so:
Code: ifstream f;
double x;
double a, b, c, d;
f.read((char *)&x, sizeof (double));
a = x;
f.read((char *)&x, sizeof (double));
b = x;
//etc ... for several other values Question:
How can I read every (lets say) 3rd value instead of every next value from the file
View 5 Replies
View Related
Mar 1, 2013
I do not understand how I can implement this.If fread != to at least 8 bytes then do THIS: printf (" your file is near the end of file", fread result);
View 8 Replies
View Related
Dec 26, 2013
If we have a text file containing the string: abc, how to reverse it to be cba using file open modes (ios::app, ios::ate, ios::binary, ios::trunc, ios::in and ios::out)?
View 19 Replies
View Related
Mar 9, 2013
I have the following code:
Code:
void Plot(int nx, int ny, double x[350], double y[350], double C_new[350][350], int iplot){
int i, j;
char fname[50];
FILE *fp;
[Code]....
I am then taking the generated file and importing it into a plotting program (Techplot360). It would speed up the importing process if I created a binary file instead of a like above. I know that I need to use fwrite but I am unsure how to handle lines like
Code:
fprintf(fp, "TITLE= ABCDEFG_%d
", iplot); and
Code: fprintf(fp, "%f %f %f
", x[i], y[j], T_new[i][j]);
View 6 Replies
View Related
Jan 24, 2013
I have a question. I would like to actually have some measure of roughly how long it takes to do a fwrite to a drive. When I do the following:
clock_t begin = clock();
unsigned long long size_t = fwrite(send, 1, transfer_size*sizeof(unsigned long long), wpFile);
clock_t end = clock();
double long elapsed_secs = double long(end - begin) / CLOCKS_PER_SEC;
Unfortunately, I don't get any different result for different transfer size!!!
My guess is that the clock_t , once it issues a fwrite command, some how stops its measurement, and it comes back again, when I am already done with fwrite. I do get the almost same measure, whether my transfer size is 32KB Byte or 16MB ! Which I was indeed expecting to see a huge difference. I wouldn't really want the exact real timing measure (well off course it will be nice to know); and all I care about is to see some difference in time whether I am doing KB transfer vs MB transfer.
Some rough measurement required of the actual time being elapsed for fwrite function?
View 10 Replies
View Related
Jul 5, 2013
I have union of pointer.
union {
short *two_int;
int *four_int;
double *eight_real;
char *one_ascii;
// void *v;
};
We have write function which write into file.
fwrite (r.one_ascii, 1, i, outstr);
I found one thing,When we write function, we fill only four int in following way.
r.four_int[0] = x + xoff;
r.four_int[1] = y + yoff;
So my question,we fill four_int but write one_ascii only.As is it union of pointer. So it does not matter. I am using 64bit machine and do not have any issue in 32 bit machine.
For more information: [URL] ....
View 7 Replies
View Related
Jan 23, 2013
I would like to actually have some measure of roughly how long it takes to do a fwrite to a drive. When I do the following:
clock_t begin = clock();
unsigned long long size_t = fwrite(send, 1, transfer_size*sizeof(unsigned long long), wpFile);
clock_t end = clock();
double long elapsed_secs = double long(end - begin) / CLOCKS_PER_SEC;
Unfortunately, I don't get any different result for different transfer size!!!
My guess is that the clock_t , once it issues a fwrite command, some how stops its measurement, and it comes back again, when I am already done with fwrite. I do get the almost same measure, whether my transfer size is 32KB Byte or 16MB ! Which I was indeed expecting to see a huge difference.
I wouldn't really want the exact real timing measure (well off course it will be nice to know); and all I care about is to see some difference in time whether I am doing KB transfer vs MB transfer. Any other function that will give me some rough measurement of the actual time being elapsed for fwrite function?
View 4 Replies
View Related
Mar 13, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
[Code]....
this code asks the user to input words/strings until he enters "end."after that, the program must copy the input to a text file named read.txt...I entered 'j' and then 'end' and after that I looked at the read.txt file and here's what's in it.
Output:
Code:
j
; end
some weird characters appeared!! the characters in the text file should only be.
View 6 Replies
View Related
Nov 5, 2013
works fine without the for loop.... if i use for loop...it doesnt give the output...
Code: #include<iostream>
#include<conio.h>
#include<fstream>
[Code]....
View 3 Replies
View Related
Sep 24, 2013
The next step for my project is to take data from a file, and create a new file with the same data, but in reverse order. If a file has the following values:
1
2
3
4
5
The program should create a new file with the following values:
5
4
3
2
1
Seems pretty straight forward, yet I am hitting a snag when I try to compile my program:
Code:
#include <stdio.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
[Code] ....
The following errors occur when I try to compile the fore mentioned code:
intrev.c: In function 'main':
intrev.c:25: warning: unused variable 'out'
intrev.c: At top level:
intrev.c:39: error: expected identifier or '(' before 'while'
[Code] .....
Now I am not concerned with "unused variable 'out'" as it is used, just in a for loop. Is this a problem?
I'm not entirely sure why it's giving me the error at line 39. I've gone over this a couple times and it doesn't look like I've missed any methods which need to be closed. Maybe I've missed something?
I'm also not sure why I am getting an error when I try to close the opened files. I've done this before in the same manner, but without errors. Not sure why I am now, but my guess is that it has something to do with the error on line 39.
View 5 Replies
View Related
Jan 5, 2015
Need to correct the errors. i've done so far.
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main() {
ifstream fin; char ch; int size=0;
[Code]...
View 5 Replies
View Related
Apr 6, 2013
1. Construct a class diagram that can be used to represent food items. A type of food can be classified as basic or prepared. Basic food items can be further classified as meat, fruit, veg or Grain. The services provide by the class should be the ability to enter data for new food, to change data for food and to display existing data about food.
using this class definition write a main program to include a simple menu that offers the following choices:
1. Add food
2. Modify Food
3. Delete Food
4. Exit this menu
2. Read a list of numbers from a file and then print them out in reverse order. State whether the list is palindromic or not.
View 2 Replies
View Related
Jan 25, 2015
C program to count the number of lines in a text file and reverse the contents in the file to write in an output file.
ex :
input
one
two
three
output:
three
two
one
View 6 Replies
View Related
Apr 6, 2014
How can I reverse/toggle bit like 1 to 0 and conversely, 0 to 1?
For instance: 01000100 ('D' 68) to 10111011 ('╗' 187).
Is there any way easier and more simple than:
1. Convert char/string to binary.
2. Toggle bits.
3. Convert binary back to char/string.
View 1 Replies
View Related
Dec 22, 2013
If I am executing following code after reversing it is giving "1" but I need "0001".
#include <stdio.h>
int main() {
int n=1000, reverse = 0;
while (n != 0) {
reverse = reverse * 10;
[Code] .....
View 11 Replies
View Related
Apr 10, 2013
I would like to add a new function to my class, "reverse" that would reverse the order of the list. I have added a prototype in the "public:" section of the code (see the comment with PROTOTYPE in it). Your task is to complete the implementation (see the comment with IMPLEMENTATION in it. See the main() function to see how the results should look
#include
#include
using namespace std;
class List {
public:
// Constructs an empty list
List();
[Code]....
I cant seem to get the right function to put into reverse I have tried everything Im not sure where to start!
View 4 Replies
View Related
Mar 28, 2014
I have written a code to find reverse of a number and print if if the original and reversed numbers are equal or not .the problem is in the if condition where the first printf is not working at all. the code is
#include <stdio.h>
#include <conio.h>
int main (void)
{
[Code]....
as if i enter 121 it still shows the 2nd printf instead of 1st one. sort out the bug;;!
View 4 Replies
View Related
Jan 12, 2014
I was browsing the web looking for simple yet fun programming challenges and crossed this one. I figured out how to reverse the string in place but I want it to read "blue is house the". I approached it in two ways for the heck of it. My idea was the second one, the first one I googled. I didn't know a simple rbegin() could do that, pretty neat.
I found the question here.[URL] ....
Code:
#include <iostream>
#include <string>
int main(int argc, const char * argv[])
{
std::string phrase = "The house is blue.";
[Code] ......
View 8 Replies
View Related
May 15, 2013
"Destructors for a derived class object are called in the reverse order of the constructors for the object. This is a general rule that always applies. Constructors are invoked starting with the base class constructor and then the derived class constructor, whereas the destructor for the derived class is called first when an object is destroyed, followed by the base class destructor."
But why, or is it just because, so programmers know which one and modify their destructor accordingly??
View 19 Replies
View Related
Apr 11, 2014
I am trying to write a program that reverses the elements of an array by using an function 'myreverse'. The function should reverse original array and return nothing.
In my program, the function 'myreverse' is not getting invoked and the original array is being displayed as it is.
#include <iostream>
using namespace std;
void myreverse(int arr[],int n) {
int *p=&arr[n-1];
int temp;
for(int i=0;i<n;++i)
[Code] .....
View 5 Replies
View Related
May 21, 2014
I am trying to write a program in which i enter sentences and then gives the reversed output
E.g.: -
INPUT
Enter the number of sentences
3
This is a sentence
Program
You are great
OUTPUT
sentence a is This
Program
great are You
I wrote the following code but its failing when im trying to enter a sentence
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void str(char*, int);
void main() {
char *word[25];
[Code] ....
View 7 Replies
View Related