0
void countWords(char home_row[], char left_chars[], char right_chars[], char currentLine[], int* homeWords, int* handWords, int* totalWords)
{
    // ASCII A-Z : 65-90
    //       a-z : 97-122
    int i = 0;
    while(currentLine[i] != '\0' || currentLine[i] != '\n')
    {
        if(currentLine[i] == ' ' && (currentLine[i+1] != ' ' || currentLine[i+1] != '\n' || currentLine[i+1] != '\0'))
        {
            totalWords++;
            int j = i+1;
            int runTime = 0;
            int homeRowChar = 0;
            int leftWordChar = 0;
            int rightWordChar = 0;

            while(currentLine[j] != ' ' || currentLine[j] != '\n' || currentLine[j] != '\0')
            {

When it gets to the while loop it shows: Thread 1, EXC_BAD_ACCESS but before it everything is fine. What's going on? How do I fix it?

Barmar
  • 741,623
  • 53
  • 500
  • 612
hubgithub
  • 21
  • 1
  • 2
  • The bottom `while()` will never stop. – Barmar Sep 15 '16 at 02:06
  • 2
    Please post a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Use debugger to examine what is going on. – MikeCAT Sep 15 '16 at 02:07
  • Whatever the value of `currentLine[j]` is, it will be not equal to one of those, so the loop continues. – Barmar Sep 15 '16 at 02:07
  • Please study how to use a debugger, as that will point you to the errant line. Furthermore, without sample input we cannot say what is wrong - is `currentLine` terminated correctly? – Ken Y-N Sep 15 '16 at 02:07
  • You should be using `&&` instead of `||` on that line. – Barmar Sep 15 '16 at 02:08
  • 1
    @Barmar The loop may stop if `break;` exists in the missing part. Again, a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) is required. – MikeCAT Sep 15 '16 at 02:08
  • @Barmar I think you are too quick to close as a dup, as we do not have a [mcve]. – Ken Y-N Sep 15 '16 at 02:10
  • 1
    @KenY-N I don't need to see any more code to tell that the problem is the incorrect logic in the last `while` condition. It's an infinite loop, so it will access outside the array, which causes the error he got. – Barmar Sep 15 '16 at 02:18

0 Answers0