doubt

This is a discussion on doubt within the C Programming forums, part of the General Programming Boards category; My program is running properly if I use the "F7" option in turbo C compiler and execute the code step ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    13

    doubt

    My program is running properly if I use the "F7" option in turbo C compiler and execute the code step wise.
    But when I use the "RUN" option of turbo C compiler, it keeps running for ever.

    Why does such a thing happen?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    It would appear to me, given the code you posted nicely within [code][/code] tags, that the problem is on line 42.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I thought the solution was on line 42. Woah, wait a second! I think you're on to something. The answer lies in the problem. The meaning of both the problem and solution in the same line. This getting deep. I think we need to move this thread to the "C Philosophy" forum.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    13
    sorry, i thought this would be a common problem,
    anyway here is the code.

    And please tell me, if possible, if i can improve the code with any other special library functions!

    Thanks


    Code:
    /*Sequentially read the whole audio book*/
    
    
    #include "stdio.h"
    #include "string.h"
    
    long global_offset;
    int count = 0;
    
    main()
    {
    	char *lookinfile, *searchfile, *foundfile;
    	int headercount, i;
    
    	char *lookforfile(char * , char * , int);
    	clrscr();
    
    	for(i=0; i<5; i++)
    	{
    
    		lookinfile = "0ncc.txt";
    		searchfile = "smil";
    		headercount = 1;
    
    		foundfile = lookforfile(lookinfile, searchfile, headercount);
    
    		printf("\n%s",foundfile);
    
    		searchfile = "mp3";
    
    		foundfile = lookforfile(foundfile, searchfile, headercount);
    		printf("\n%s",foundfile);
    	}
    }
    
    
    
    char *lookforfile(char *lookinfile, char *searchfile, int headercount)
    {
    
    
    	char ch;
    	int j;
    	long offset;
    	FILE *fp;
    	char *lookupfile, *global_next_header, *returnfile;
    
    	fp = fopen(lookinfile,"r");
    
    	lookupfile = "smil";
    
    
    if(searchfile[0]==lookupfile[0])
    {
    	if(count == 0)
    	{
    
    		while(count != headercount)
    		{
    			/*LOOK FOR headerstring;*/
    
    			ch=fgetc(fp);
    			if(ch=='<')
    			{
    				if((ch=fgetc(fp))=='h')
    				{
    					if((ch=fgetc(fp))=='1')
    					{
    						/*FOUND H1?*/
    						count = count+1;
    					}
    				}
    			}
    		}
    	}
    
    
    	if(count>1)
    	{
    
    		fseek(fp, global_offset, SEEK_SET);
    	}
    
    
    
    	while(ch!='\n')
    	{
    		/*Look for h ref="......"*/
    		/*... *lookupfile = "xyz.smil" */
    
    		if((ch=fgetc(fp))=='h')
    		{
    			if((ch=fgetc(fp))=='r')
    			{
    				if((ch=fgetc(fp))=='e')
    				{
    					if((ch=fgetc(fp))=='f')
    					{
    						if((ch=fgetc(fp))=='\=')
    						{
    							if((ch=fgetc(fp))=='\"')
    							{
    								j=0;
    								while((ch=fgetc(fp))!='\#')
    								{
    									returnfile[j]=ch;
    									j++;
    								}
    								returnfile[j]='\0';
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    
    
    	/*WHAT IS NEXT AVAILABLE HEADER?*/
    
    	while((ch=getc(fp))!='\<');
    	j=0;
    	while((ch=getc(fp))!='\ ')
    	{
    		global_next_header[j]=ch;
    		j++;
    	}
    		count = count+1;
    		global_offset = ftell(fp);
    		global_next_header[j]='\0';
    
    
    	return(returnfile);
    }
    
    
    	lookupfile="mp3";
    
    	/*LOOK UP MP3 FILE */
    
    	if(searchfile[0]==lookupfile[0])
    	{
    		/*Look for audio src"......"*/
    
    		/*...*lookupfile = "abc.mp3"...*/
    
    		while((ch=fgetc(fp))!='\n')
    		{
    			if(ch=='s')
    			{
    				if((ch=fgetc(fp))=='r')
    					{
    					if((ch=fgetc(fp))=='c')
    					{
    						if((ch=fgetc(fp))=='\=')
    						{
    							if((ch=fgetc(fp))=='\"')
    							{
    								j=0;
    								while((ch=fgetc(fp))!='\"')
    								{
    									returnfile[j]=ch;
    									j++;
    								}
    								returnfile[j]='\0';
    							}
    						}
    					}
    				}
    			}
    		}
    		return(returnfile);
    	}
    
    }

    

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubt in pointer.
    By shwetha_siddu in forum C Programming
    Replies: 5
    Last Post: 03-21-2009, 01:28 AM
  2. Replies: 4
    Last Post: 12-10-2006, 06:08 PM
  3. Doubt abt Storage!
    By kalamram in forum C Programming
    Replies: 1
    Last Post: 04-21-2006, 05:30 AM
  4. arrays doubt
    By j0nnyX in forum C Programming
    Replies: 4
    Last Post: 11-20-2004, 12:10 PM
  5. Greatest C++ Doubt
    By vasanth in forum C++ Programming
    Replies: 15
    Last Post: 02-28-2002, 03:41 AM

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