error with fopen,fread and type long !!

This is a discussion on error with fopen,fread and type long !! within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> #include<conio.h> #include<alloc.h> #include<dos.h> #include<string.h> #include<share.h> struct wavdata {unsigned int soundlength, frequency; char *sample; }; struct RIFF { long ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    1

    Unhappy error with fopen,fread and type long !!

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<alloc.h>
    #include<dos.h>
    #include<string.h>
    #include<share.h>
    
    struct wavdata {unsigned int soundlength, frequency;
    		char  *sample;
           };
    
    
    
          struct RIFF
           {
    
          long wave;
          long fmt;
          unsigned int BitRes;
          long data[40];
          long datasize[40];
          long channels;
          long samplerate;
          }   header;
    
    
    
    
    
    
           char fp[25];
          char data1[100];
    
    
    
    
          fp =fopen("cwave1.wav", "rb");
          if(fp ==NULL)
          {
          printf("unable to open to wave file\n");
          return(0);
          }
    
    	  fread( data1,sizeof data1,1,fp);
    	}
    
    	  if(header.RIFF != 0x46464952)
    	  {
    	    printf("%x\n");
    	    printf(" RIFF format\n");
    	  }
    
    	  if(header.wave == 45564157)
    		  {
    	     printf("No wavfmt format\n");
    
    
    	     }
    	  if(header.fmt !=2074666)
    	  {
    
    	     printf("No wavfmt format\n");
    		}
    
    
    	  //check channels
    	  if(header.channels !=1)
    	  {
    	  printf("Not a mono wave file\n");
    	  return(0);
    	  }
    
    	  //check bit resolution
    	  if(header.BitRes !=8)
    	  {
    	   printf("Not an 8-bit wave file\n");
    	   return(0);
    	   }
    	  // Verify the sample size
    	  if(header.samplerate!= 48000)
    	  {
    	  printf("%x\n");
    	   printf("Sample rate is not 48KHZ\n");
    
    
    
    
    
    
    
    
    
    
    
    
    int main()
    {
    
          clrscr();
          printf("Play a wave file\n");
          printf("Please input filename + extension\n");
          gets(fp);
    
    
    
          return(0);
    }

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Your code is insanely poorly indented, and you did not tell us the error.
    You are also trying to run your code out of the main function.. Why?

    Please read a book on C and then come back.

  3. #3
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Describe the problem, as it seems that your little program actually doesn't do anything.
    I can assert that you copied a half-solved project from someone and try to adopt it for yourself, but that's ok with me, as long as you can prove that you understand what is being done and how you plan to complete the solution.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And the error is?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Yeah that block of code in the middle of nowhere kind of makes it hard to help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  2. hton long long
    By carrotcake1029 in forum C Programming
    Replies: 1
    Last Post: 06-01-2008, 09:26 PM
  3. strings Vs. Char pointers
    By aijazbaig1 in forum C Programming
    Replies: 49
    Last Post: 02-13-2008, 09:51 AM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 05:33 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21