Adding to a big char* for search engine

This is a discussion on Adding to a big char* for search engine within the C Programming forums, part of the General Programming Boards category; Hey everyone, I've got a situation, I am building a search engine and i am trying to produce one big ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    9

    Adding to a big char* for search engine

    Hey everyone,

    I've got a situation, I am building a search engine and i am trying to produce one big char pointer that points to all text that is not a tag in an html file.

    I do this by reading the html file, line by line, removing tags from each line(by calling removeTag), then adding the line w/o tags to the end of my big char pointer. But alas, it is not working.

    You can assume that all my functions that i call are working normally, since i've already debuged them. the error has to be where i add duplicate to the bigPtr. Any suggestions are welcome. Thanks everyone.

    The Landroid

    Oh yeah, ignore my print statements, they are just for debuging and seeing what is going where.

    Code:
    char* getNoTags(char* url)
    {
    //printf("IN GET NO TAGS");
      char contentType[ MaxLineLength ];
      char* duplicate;
      int counter;
      char* bigPtr;
      int x = 0;
      int y = 0;
      char line[MaxLineLength];
      bigPtr = new char[10000];
      FILE * f = openhttp( url, contentType );
      if ( f == NULL ) {
        exit(1);
      }
    
      // Print the content type
      //printf( "Content Type: \"%s\"\n", contentType );
    
    
      while ( fgets( line, MaxLineLength, f ) ) {
    	
        duplicate = removeTag(line,MaxLineLength);
    	//printf("%s",duplicate);
    	y = 0;
        do{
          bigPtr[x] = duplicate[y];                                
    	  
          x++;
          y++;
    	printf("%c",bigPtr[x]);
        }while(duplicate[y] != '\0');
         
    	//printf("i've made it out\n");
      }
    
    	printf("\ni'm outside everything\n");
    
      fclose(f);
    
      //bigPtr[x] = '\0';
      //printf("bigPTR: %s\n",bigPtr);
      printf("returning\n");
      return bigPtr;
    
    }

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    9
    and BTW, this is a school project, not for production.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    Code:
    bigPtr = new char[10000];
    That's C++, not C.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > duplicate = removeTag(line,MaxLineLength);
    Your problem is probably here. Plus if you're allocating space for duplicate in removeTag(), you're leaking memory, since you didn't free it.

    Also, this is C++ code.

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    9
    the unix server i compile on compiles it in C++, so i can use C++ and C for my code. I write most of my code in C, but i do use an occasional C++ command if it seems easier.

    RemoveTags runs fine, i use it on other functions that work and it does exactly what it is supposed to.

    And yes i know this is a memory leak, i am just trying to get this bad boy runnin so i can test my binary trees and such. I can fix that later once its runnin.

    I will try and recode it w/ realloc() and see how that works out.

    Any other suggestions would be awesome.

    Thanks for the replies too

    The Landroid

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well your "occasional use of C++ commands" makes it no longer a C issue. If any of it is C++, it all is. As such, you're in the wrong place if you choose to do it that way.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Universal Engine
    By Travis Dane in forum Game Programming
    Replies: 6
    Last Post: 02-16-2003, 11:54 AM
  3. Looking for some big C/C++ projects
    By C-Dumbie in forum C Programming
    Replies: 5
    Last Post: 09-16-2002, 01:18 AM
  4. Need lots of help with tile engine
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 06-12-2002, 02:54 AM
  5. What's a 3D engine?
    By Garfield in forum Game Programming
    Replies: 6
    Last Post: 12-18-2001, 04:06 PM

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