I am also havin the same difficulty, when i am trying my code in linux (ubuntu) using gcc.

my code is actually a long around 500 lines.
so putting all lines of code is not a gud idea here.
suggest me wr i put my codes so that you can have a look on it. and can provide needy solution to me.

my code is actually a long around 500 lines.
so putting all lines of code is not a gud idea here.
suggest me wr i put my codes so that you can have a look on it. and can provide needy solution to me.

So add output statements to watch the program flow and try to pinpoint th problem area. Then you can post the code that shows the problem.

And what's gud and wr? Please see this.

well..
i used the following for compiling and debugging:
gcc -lm exp4.c -g
and then gdb a.out
and then i put "r"
this gave me the following output:
Starting program: /home/abhi/Desktop/exp/a.out
Program received signal SIGSEGV, Segmentation fault.
0xb7ea8da0 in strcpy () from /lib/tls/i686/cmov/libc.so.6

plz tell me what to do for removing this segmentation fault.

and when i used the list and up command in gdb i got the following:
(gdb) list
471 /* RETURNS: frame level description of input query file */
472 /* (Transcribe.dat) containing following fields- frame index, */
473 /* frame pitch, frame state, normalized frame energy */
474 /* ############################################################# */
475 /* ############################################################# */
476
477 int main(int argc, char* argv[])
478 {
479 FILE *fpFrame;
480 char QueryFile[]="000_FOOBAR.wav";
(gdb) up
#1 0x08049532 in main (argc=1, argv=0xbffb5774) at exp4.c:486
486 strcpy(QueryFile,argv[1]);
(gdb) backtrace
#0 0xb7ea8da0 in strcpy () from /lib/tls/i686/cmov/libc.so.6
#1 0x08049532 in main (argc=1, argv=0xbffb5774) at exp4.c:486

  1. Don't hijack threads which are 2.5 YEARS old with some random 1-liner "me too" post.

  2. When you do get around to posting something meaningful, if it's code or error messages, then use the CODE tags to make sure it remains readable. Did you miss all the intro threads, watermarks and copious other examples, or did you just decide to ignore them.

  3. The reason for your first segfault is obvious. Your program is expecting command line parameters, and you didn't supply any.
    So your argv[1] is NULL, and that's a guaranteed segfault when you try to dereference it.

The first step in your code would be to check argc to see that the correct number of command line parameters have been passed, before trying to use any argv string.

sorry i used the old thread;
anyways.
i run the compiled program by writting:
./ a.out aaa.wav 2
where aaa.wav is my input file.
it still giving segmentation fault. i anm putting my main part of code here.
plz have a look on it.

int main(int argc, char* argv[])
{
	FILE *fpFrame;
	char QueryFile[]="000_FOOBAR.wav";
	unsigned int FilterType;
	GOF *gof=(GOF *) NULL;
        GON *gon=(GON *) NULL;
	unsigned int i;

	strcpy(QueryFile,argv[1]);
	switch(argv[2][0])
	{
		case 't':
		case 'T':
			FilterType=1;	
			break;
		case 'l':
		case 'L':
			FilterType=2;	
			break;
		case 'h':
		case 'H':
			FilterType=3;	
			break;
		default:
			FilterType=1;	
	}

	gof=(GOF *) malloc(sizeof(GOF));
	gof=Transcribe(gof,QueryFile,FilterType);

	fpFrame=fopen("Transcribe.dat","w");
	fprintf(fpFrame,"%d\t%d\n",gof->NumFrames,gof->SampleRate);
	for(i=0;i<gof->NumFrames;i++) fprintf(fpFrame,"%d\t%f\t%d\t%f\n",i,gof->Frame[i].Pitch,gof->Frame[i].State,gof->Frame[i].Energy);
         MATCH_SEQ *seq=(MATCH_SEQ *) NULL;
         gon=(GON *) malloc(sizeof(GON)); 
         gon=ReadNoteDescription(gon);
         /* quantize user string to semitone level */

	seq=(MATCH_SEQ*) malloc(sizeof(MATCH_SEQ));

	seq=Quantization(seq,gon);
        free(gon);
       
         /* write user string (in semitones) description */

	WriteUserString(seq,"Quantize.dat");
        free(seq);
         
	fclose(fpFrame);
	 
	return 0;
}

>sorry i used the old thread;
>anyways.
Somehow I don't believe that you're sorry at all.

1. Your 2nd command line parameter doesn't match anything in your code.

2. Why didn't you run this in the debugger, like your previous post, to show us where the new segfault occurred. Since it's going to be in one of the sub-functions you've written, you may have to post that function as well.

3. This is a C program. There is no need to cast the result of malloc in an otherwise correct C program. Doing so masks
- your failure to include stdlib.h
- your use of a C++ compiler to compile C code.

By the same token, you don't need to cast NULL either.

4. Check the result of your fopen() calls.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.