Thread: Need some help debugging

  1. #16
    Registered User zolfaghar's Avatar
    Join Date
    Mar 2016
    Posts
    95
    Quote Originally Posted by whiteflags View Post
    Code:
    for ( i=0; i<19; i++)
    Does this loop have a purpose?
    No; I removed it. Thanks.

  2. #17
    Registered User zolfaghar's Avatar
    Join Date
    Mar 2016
    Posts
    95
    Quote Originally Posted by jimblumberg View Post
    You really don't need either of those if() statements at the bottom of your loop because you're while() statement limits the loop to only accepting 'C' or 'c'.

    Jim
    Thanks; it is a lot simpler now.

  3. #18
    Registered User zolfaghar's Avatar
    Join Date
    Mar 2016
    Posts
    95
    I works very well now as far as I can tell. Thank you so much.

    Code:
    #define LINE_SIZE 200
    # include <stdio.h>
    # include <stdlib.h>
    int main ()
    {
      FILE *fp;
      fp = fopen ("somefile.txt", "r");
      if (fp == NULL)
      {
        puts("Could not open the file");
        exit(0);
      }
      int i, ch, m, n;
      ch = 0;
      char line [LINE_SIZE];
      printf ("Press 'q/Q' to quite and any other key to continue");
      while ((ch=getchar()!='q') || (ch == 'Q'))
      {
          fgets(line, LINE_SIZE, fp);
          printf (" \n Enter the value of starting column ");
          scanf("%d", &m);
          printf (" \n Enter the value of ending column ");
          scanf ("%d", &n);
          int columCounter;
          for (columCounter = m; columCounter < n+1; columCounter++)
          putchar(line[columCounter]);
          printf ("\nPress 'C/c' to continue or 'q/Q' to quite");
          ch = getchar();
       }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging help :(
    By Zul56 in forum C Programming
    Replies: 51
    Last Post: 01-12-2013, 10:21 PM
  2. Need help debugging...
    By n2d33p88 in forum C++ Programming
    Replies: 8
    Last Post: 12-13-2007, 04:15 AM
  3. Debugging help
    By iitb.ankit in forum C Programming
    Replies: 4
    Last Post: 06-04-2006, 07:20 AM
  4. help debugging
    By MB1 in forum C++ Programming
    Replies: 6
    Last Post: 11-03-2005, 01:48 PM
  5. debugging
    By Ssfccsh in forum C++ Programming
    Replies: 10
    Last Post: 03-01-2004, 12:20 AM

Tags for this Thread