String search in two text files

This is a discussion on String search in two text files within the C Programming forums, part of the General Programming Boards category; Please tell me if this code is correct for searching a string in PTIN with contents in PTOUT. I am ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    6

    String search in two text files

    Please tell me if this code is correct for searching a string in PTIN with contents in PTOUT. I am not getting the correct result. Please help.

    Code:
    while(fgets(text, MAX_LEN_SINGLE_LINE, ptin)!=NULL)
    	        {
                      
                    if(text[strlen(text)-1]=='\n')
                    text[strlen(text)-1]='\0';
                  
                 
    				while(fgets(textchk, MAX_LEN_SINGLE_LINE, ptout)!=NULL)
    				{ 
    					a=strstr(textchk,text);
    					
    					if(a==NULL)
    						fprintf(p1,"%s",text);
    					else
    						continue;
    				}rewind(ptout);
                 }

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Your indention is terrible.

    You're printing the line only if you don't find a match. Also, your usage of continue is rather..... odd.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by MacGyver View Post
    Also, your usage of continue is rather..... odd.
    As in "it's completely meaningless in this context".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM

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