473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

.wav file reading

i was able to open the .wav file using c program, but while reading,its not reading the full file.i opened the .wav file in visual cpp and compared it with the program output.so many data missing.its reading only less than 1/4th of the file.no error is shown by the program.so how can i read a wav file correctly in the hex format.my program is given below.
[code]
#include<stdio.h>
#include<conio.h>

void main()

{
int i;
long n;
FILE *f1;
clrscr();
printf("the data output is \n\n");
f1=fopen("silence.wav","r");
while(feof(f1)==0)
{
i=getw(f1);
if(ferror(f1)!=0)
{
printf("\n an error has occurred"); just to check if any error occured.
n=ftell(f1);
printf("\n\nthe value of n is %ld",n);
getch();
}
printf("%x ",i);
}
n=ftell(f1);
printf("\n\nthe value of n is %ld",n);
fclose(f1);
printf("\n\n end of the file");
getch();
}
[code]
Sep 6 '06 #1
4 8660
hai Joby,
Your problem is simple.Here you are trying to open the file in read mode using the "r" in fopen().This mode is generally used for text files .the .wav is not text file.So that you should open it in binary read mode using "rb" or "rb+" instead of "r" in fopen()
Sep 6 '06 #2
I will suggest you to go through the open,read,write,close functions in c.
Sep 6 '06 #3
Banfa
9,065 Expert Mod 8TB
I do not think that getw is an ANSI function and is certainly non-portable since it reads an integer which may differ from system to system in both size and endianess.

An improved method would be to use fread to read in the number of bytes and then to reconstruct the integer from that

Expand|Select|Wrap|Line Numbers
  1. unsigned char byte[4];
  2.  
  3. if (fread(byte, sizeof byte, 1, f) == sizeof byte)
  4. {
  5.     int i = byte[0] | (byte[1]<<8) | (byte[2]<<16) | (byte[3]<<24);
  6. }
  7.  
Sep 6 '06 #4
Hai joby,
you can do this by opening it in binary mode ,the code may be as follows
#incude<io.h>
//add additional headder files
void main()
{
int han,c;
char file[20],buf[20];
gets(file);
han=open(file,O_RDONLY|O_BINARY);
while(1)
{
c=read(han,&buf,10);
if(c==0)
{
break();
}
//manipulate the characters upto buf[c-1]
}
}
Sep 7 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
6
Atran
by: Atran | last post by:
Hello: In this article: You will learn to Write or Read A Text File. Let's Begin: First Create a new project (ConsoleApp or WinApp). And Make sure your program uses these namespaces: using...
2
by: Zach | last post by:
I compiled a game client and it crashed (segmentation fault) resulting in a core file being generated. I'm trying to find out exactly what caused it to crash. Any ideas how I can do this with gdb?...
1
by: dwaterpolo | last post by:
Hi Everyone, I am trying to read two text files swY40p10t3ctw45.col.txt and solution.txt and compare them, the first text file has a bunch of values listed like: y y y y y y y
13
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.