Thread: strchr trouble

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    61

    strchr trouble

    Hi all!

    This code should work, but it doesn't:

    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	char *pos;
    	char buf[100];
    	FILE *fp;
    		fp = fopen("text.txt","r");
    	
    		fgets(buf, 100, fp);
    		pos = strchr(buf, '~');
    		if (pos){
    			printf("Character '~' found at position %d.\n", pos - buf);
    		}
      
    
    	fclose(fp);
        return 0;
    
    }
    When I try to compile it I get this:
    warning: incompatible implicit declaration of built-in function 'strchr'.

    What's wrong with the code?

    Thanks in advance for help

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Perhaps...
    Code:
    #include <string.h>
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Have you included string.h header?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    61
    hurray The string header worked

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 10:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 03:02 PM
  3. Using strchr() and moving the cursor up one row
    By Mavix in forum C Programming
    Replies: 7
    Last Post: 09-26-2006, 12:34 PM
  4. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-29-2003, 11:55 PM