Thread: How to create a FILE?newbie question..

  1. #31
    Registered User
    Join Date
    Sep 2005
    Posts
    31
    Code:
    for(j=0 ; j<6 && ch=='Y'; j++)
    It this a valid statement?Coz it still runs the loop eventhough i type 'N'

  2. #32
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Code:
    #include<stdio.h>
    
    int main()
    {
        int i=0;
        int ch='Y';
        
        for(i=0;i<10 && ch=='Y';i++)
        {
            printf("Enter (Y/N) ->> ");
            ch = getchar();
            clear_buffer();
        }
        printf("You are out ofloop\n");
        
        getchar();
        return 0;
    }
    /*
    my output               
    Enter (Y/N) ->> Y
    Enter (Y/N) ->> Y
    Enter (Y/N) ->> Y
    Enter (Y/N) ->> Y
    Enter (Y/N) ->> Y
    Enter (Y/N) ->> Y
    Enter (Y/N) ->> N
    You are out ofloop
    */
    NOTE: it accepts uppercase letters only. in order to change it suppost both upper and lower u got change something in loop.(add some more condition) i leave it to

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 12:13 PM
  2. Question about binary trees and files
    By satory in forum C Programming
    Replies: 9
    Last Post: 03-06-2006, 06:28 AM
  3. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 03:52 PM
  4. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM
  5. I have a Question about memory usage for C.
    By bobthefish3 in forum C Programming
    Replies: 34
    Last Post: 12-24-2001, 04:37 PM