Thread: Homework Help? beginner c loops

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    2

    Homework Help? beginner c loops

    Hello, I'm bit new at C, the problem I'm having is I want to count the number of times printf will print. So say printf print 3 times, I want to be able to count that and then print it. This is just a part of a larger piece of code. I hope what I'm asking makes sense, any hints towards the right direction would be much appreciated!

    Also, I tried counting the number of time printf prints by using y++, but it comes out in a weird number.

    Code:
    //looping through both arrays, if letters don't match, print
    for (k = 0; k<strlen(myArrayTwo); k++){
         if(myArray[k] != myArrayTwo[k])    
    
    
        y++;
    
    
    printf("The word %s differs from its reverse in %d places.\n",myArray, y);
    }

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Do you initialize "y"? Currently "y" is only incremented inside the if-block while printf() is executed in every iteration of your for-loop. That's why indenting your code properly is very important.

    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework - loops
    By PaperBag in forum C Programming
    Replies: 5
    Last Post: 03-02-2011, 04:34 PM
  2. beginner help loops
    By aadil7 in forum C Programming
    Replies: 9
    Last Post: 03-15-2010, 01:41 AM
  3. True Beginner - Pointer/Array For loops
    By KyussRyn in forum C Programming
    Replies: 7
    Last Post: 03-04-2009, 03:53 AM
  4. Replies: 4
    Last Post: 11-15-2005, 02:13 PM