While - if - pointers...

This is a discussion on While - if - pointers... within the C Programming forums, part of the General Programming Boards category; Ok. Here, i want to know, in the first 'while', it starts with first char, so we have for ex. ...

  1. #1
    Sometimes so stupid... shardin's Avatar
    Join Date
    Jul 2007
    Location
    Dalmatia/CRO
    Posts
    78

    While - if - pointers...

    Ok. Here, i want to know, in the first 'while', it starts with first char, so we have for ex. 'a'. Then the word, second 'while', it starts with first char and we have ex. 'b'. I want to compare them, want to compare two words. Then 'if' comes. If 'if' is true, br++. Where does it goes next, does it runs until second 'while' is finished or what? It should be running second 'while' until '\0', and every time char is the same as first char of '*po2' it should do 'br++', but of course it doesnt work.

    po2=sentence;
    po1=word;

    Code:
    while(*po2!='\0')
    	{
    		while(*po1!='\0')
    		{
    			if(*po1==*po2)
    			{
    				br++;
    			}
    			po1++;
    		}
    	}
    printf("%d", br);

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    You aren't incrementing po2 anywhere, the outermost while loop will be an infinite loop.
    "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
    Sometimes so stupid... shardin's Avatar
    Join Date
    Jul 2007
    Location
    Dalmatia/CRO
    Posts
    78
    well, i did move a little bit now...thx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

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