Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,203 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,323 people online right now. Registration is fast and FREE... Join Now!




Reading blank , enter Char

 
Reply to this topicStart new topic

Reading blank , enter Char

ALZ
8 Jul, 2008 - 11:39 AM
Post #1

New D.I.C Head
*

Joined: 14 May, 2008
Posts: 9

Hi, I have the following code, Im trying to correct it in a way that if user enters nothing, or just enter or space,, It display an error message,, I tried to use the switch statement and I couldnt, can you please advise how i can do it, thanks,,,
CODE

#include <stdio.h>

void main()
{
    char a;
    int count = 1;
    char b;
    char c;
    char d;
    
            printf("Please Enter a Sentence with full stop \n");
        do
        {
                a = getchar();
                
                //if (a == ' ' ){ printf("Invalid Entry");
                //break;}


                if(a == 32 && b != 32 && c !=46)
                count++;
                
                b = a;
                c = a;
                d = a;
                
        } while(a != 46 );
        
          printf("Entered %d \n",count);
        

    
}


This post has been edited by ALZ: 8 Jul, 2008 - 12:43 PM
User is offlineProfile CardPM
+Quote Post

killer_beast
RE: Reading Blank , Enter Char
8 Jul, 2008 - 03:19 PM
Post #2

New D.I.C Head
*

Joined: 31 May, 2008
Posts: 34


My Contributions

well i think if you write
if (a == '\n ' ){ printf("Invalid Entry");
that will solve your problem i hope


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 12:28PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month