Thread: Finding a String in a file

  1. #1
    Registered User Silverdream's Avatar
    Join Date
    Feb 2002
    Posts
    53

    Finding a String in a file

    Hi,
    How can i find a string in a file?

    Code:
    int search(*emp_id)
    {
    	int flag=0,len;
    	len=strlen(*emp_id);
    	rewind(fp);
    	while(fp!=EOF)
    	{
    		if(*fp==*emp_id)
    		{
    			flag=1;
    			fp++;
    			emp_id++;
    			continue;
    		}
    		else
    		{
    			flag=0;
    			fp++;
    			continue;
    		}
    	}
    }
    I have attempted this function but with no luck. I know why it doesnt work but i am unable to solve this problem.

    Also i would like to know how can i change color of the text to be displayed on the screen and how to keep the text flashing on the screen.

  2. #2
    Registered User Silverdream's Avatar
    Join Date
    Feb 2002
    Posts
    53

    Talking

    Thanx for the code.

  3. #3
    Registered User Dave Jay's Avatar
    Join Date
    Mar 2002
    Posts
    33
    Also i would like to know how can i change color of the text to be displayed on the screen and how to keep the text flashing on the screen.

    Specify platform

    In DOS you can use textcolor(number + BLINK); defined in conio.h
    number is an integer representing a 4 bit color.

  4. #4
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    to find a string in a file can't u use 'strstr' ? unless u wanna code ur own.

  5. #5
    Registered User Silverdream's Avatar
    Join Date
    Feb 2002
    Posts
    53
    Originally posted by Nutshell
    to find a string in a file can't u use 'strstr' ? unless u wanna code ur own.
    strstr can be used for searching a string within another string. Cannot be used to find a string in a file.

  6. #6
    Registered User Silverdream's Avatar
    Join Date
    Feb 2002
    Posts
    53
    Originally posted by Dave Jay
    Also i would like to know how can i change color of the text to be displayed on the screen and how to keep the text flashing on the screen.

    Specify platform

    In DOS you can use textcolor(number + BLINK); defined in conio.h
    number is an integer representing a 4 bit color.
    The platform is windows and i am using VC++ 6.0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. finding out a string from a text file
    By Brij in forum C++ Programming
    Replies: 1
    Last Post: 01-21-2007, 03:22 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM