Thread: program skips over code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    program skips over code

    so i'm having this problem, where my program does not execute correctly. i'm not entirely positive what i'm doing wrong, but i wrote the program at like 5am when i was tired as a dog so that could have something to do with it. but here's the code..
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <time.h>
    
    /* Prototype */
    int fixgets(char *, int ,FILE *);
    void wait(long);
    
    int main(void)
    {
        FILE *fptr, *outptr;
        char infoIn[255] = {0}, infoOut[255] = {0}, fname[255] = {0}, oname[255] = {0};
        char link[] = "<a target=\"_blank\" href=\"http://www.imdb.com/find?q=", query[200] = {0};
        int i = 0, x = 0, y = 0;
        
        printf("Please enter the location of the file to be processed.\n");
        fixgets(fname, 255, stdin);
        printf("Please enter the location and name of the new file to be saved.\n");
        fixgets(oname, 255, stdin);
        
        if ((fptr = fopen(fname, "r")) == NULL || (outptr = fopen(oname, "w")) == NULL)
        {
            if (fptr == NULL)
            {
                printf("\n\nI'm sorry, but the file specified could not be opened for reading.\n");
                printf("Please close any program accessing the file and make sure the disk is readable.\n");
            }
            if (outptr == NULL)
            {
                printf("\n\nI'm sorry, but the file specified could not be opened for writing.\n");
                printf("Please ensure you have write access to the disk and try again.\n");
            }
            
            printf("\nPress any key to exit..\n");
            getch();
            if (fptr != NULL)
                fclose(fptr);
            if (outptr != NULL)
                fclose(outptr);
            return 1;
        }
        else
        {
            do
            {
                fixgets(infoIn, 255, fptr);
                if (infoIn[0] != 0)
                {              
                    if (strstr(infoIn, "<td class=\"title\">") != NULL && strstr(infoIn, "imdb.com") == NULL)
                    {
                        x = 0;
                        y = 0;
                        strcpy(infoOut, "<td class=\"title\">");
                        printf("infoOut = %s\n", infoOut);
                        system("pause");
                        strcat(infoOut, link);
                        printf("infoOut = %s\n", infoOut);
                        
                        for (i = 17; i < strlen(infoIn); i++)
                        {
                            while (infoIn[i] != '<')
                            {
                                query[y] = infoIn[i];
                                ++y;
                            }
                        }
                        printf("query: %s", query);
                        system("pause");
                                
                        }
                        for (i = 18; i < y; i++)
                        {
                            if (infoIn[i] != ',')
                                query[x] = infoIn[i];
                            else
                                y = 1000;
                            ++x;
                        }
                        printf("query: %s\n", query);
                        system("pause");
                        
                        strcat(infoOut, query);
                        
                        y = 0;
                        for (i = 0; i <= strlen(infoOut); i++)
                        {
                            if (infoOut[i] == '>')
                                ++y;
                            if (infoOut[i] == ' ' && y == 2)
                                infoOut[i] = '+';
                        }
                        
                        strcat(infoOut, "\">");
                        strcat(infoOut, query);
                        strcat(infoOut, "</a></td>");
                        fprintf(outptr, "%s\n", infoOut);
                    }
                    else
                        fprintf(outptr, "%s\n", infoIn);
                    
                    for (i = 0; i < sizeof(infoOut); i++)
                    {
                        infoOut[i] = 0;
                        infoIn[i] = 0;
                    }
            } while (!feof(fptr));
            fclose(fptr);
            fclose(outptr);
        }
        
        return 0;
    }
    
    
    /* This routine fixes fgets incorporation of line feeds and other
     * ASCII values less than 32 into an input string.  Written by H. Brown.
     */
    int fixgets(char input_array[], int length, FILE *file_name)
    {
       register int position=0;
    
       if (fgets(input_array,length,file_name) != NULL)
         {
         while(input_array[position] != 0)
    	  {              if (input_array[position] < 32) input_array[position]=0;
    	  else ++position;
    	  }
         }
       /* The length of the string is returned. */
       fflush(stdin);
       return position;
    }
    
    
    void wait ( long seconds ) {
      clock_t limit, now = clock();
      limit = now + seconds * CLOCKS_PER_SEC;
      while ( limit > now )
        now = clock();
    }
    the problem is: it doesn't output anything but: "></a></td>
    it should be outputting a lot more than that. in this conditional: if (strstr(infoIn, "<td class=\"title\">") != NULL && strstr(infoIn, "imdb.com") == NULL)
    it skips the first two printf's and goes directly to the 3rd. the problem with the 3rd conditional is that it contains no data. at all. SO...some light would be much appreciated on this dark situation i'm experiencing.. :] thanks
    Last edited by willc0de4food; 11-16-2006 at 06:41 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. scanf skips lines of code in DOS using Dev-C++ and Windows XP
    By jenovanomusuko in forum C Programming
    Replies: 9
    Last Post: 12-21-2008, 03:10 AM
  3. Run A Program from within a cpp code
    By Hexxx in forum C++ Programming
    Replies: 6
    Last Post: 01-02-2006, 08:05 PM
  4. how do I morse code converting program
    By panfilero in forum C Programming
    Replies: 17
    Last Post: 10-29-2005, 09:16 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM