help searching words in large files

This is a discussion on help searching words in large files within the C Programming forums, part of the General Programming Boards category; hello, i made a simple app that searches a small sized file for example 100 lines, finds a word you ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    17

    help searching words in large files

    hello,

    i made a simple app that searches a small sized file for example 100 lines, finds a word you want it to find and prints the whole line that has that word

    Code:
    #include <stdio.h>
    #include <string.h>
    int main(){
        char a[100];
        FILE *fin=fopen("in.txt","r");
        FILE *fout=fopen("out.txt","w");
        while(fgets(a,sizeof(a),fin)!=NULL){
              if (strstr(a,"someword")){
                     fprintf(fout,"%s\n",a);}
                     }
        fclose(fin);
        fclose(fout);
        return 0;
    }
    when i try big files, it shows up the "Please tell Microsoft about this problem." error.

    i searched but couldnt find anything, would appreciate any help provided.

    thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Check to make sure the file is actually opening.


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

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    17
    indeed the file didnt open

    is there any other function or algorithm in order to open such files?

    ps: the file is 5.5 mb

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Your path is probably wrong. Six megs shouldn't be a problem to open.


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

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    17
    Quote Originally Posted by quzah View Post
    Your path is probably wrong. Six megs shouldn't be a problem to open.


    Quzah.
    what would you recommend me to do?

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by nick2 View Post
    "Please tell Microsoft about this problem."
    Maybe they are joking too.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. How to better manage large .cpp files
    By 39ster in forum C++ Programming
    Replies: 6
    Last Post: 08-25-2008, 08:24 AM
  3. using mmap for copying large files
    By rohan_ak1 in forum C Programming
    Replies: 6
    Last Post: 05-13-2008, 08:12 AM
  4. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 09:41 PM
  5. searching files in directory
    By lobo in forum Windows Programming
    Replies: 5
    Last Post: 10-05-2001, 03:00 AM

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