Thread: Program to print input to output by removing extra balnks :)

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    4

    Program to print input to output by removing extra balnks :)

    Hie everyone.. I am a newbie and learning c programming.. I refered the site and found ansic is the best book) thanks to cprogramming.com.. I am reading it..

    Therein the author asked us to write a program to print input to output by removing extra balnks..

    I have writen the following code.. No errors! But it does not print anything except for the printf statement... why so?

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
        int v,bcount=0;
    
        printf("Type in the string that you want to edit...\n \n Now!\n");
    
        while( (v=getchar()) != EOF);
    {
        if(v!=' ')
            {
                putchar(v);
                bcount=1;
            }
    
        else if(v==' ')
           {
               while(bcount==1)
            {
                putchar(v);
                ++bcount;
             }
    
           }
    
    }
    return(7);
    }



    Plz help !

  2. #2
    Registered User
    Join Date
    Jul 2011
    Posts
    4
    Oh.. lemme post the exact question to you all.. Exercise 1-9. Write a program to copy its input to its output, replacing each string of one or
    more blanks by a single blank. What i need to know is what is wrong with the code I have written

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > while( (v=getchar()) != EOF);
    Watch the ; at the end of this line.

    > return(7);
    A successful main returns 0
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Output file has extra characters.
    By fadlan12 in forum C++ Programming
    Replies: 5
    Last Post: 07-04-2010, 08:33 PM
  2. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 06:41 PM
  3. Output file contains extra data
    By nizbit in forum C Programming
    Replies: 3
    Last Post: 02-21-2005, 08:00 PM
  4. Adding extra characters to output
    By COBOL2C++ in forum C++ Programming
    Replies: 2
    Last Post: 07-11-2003, 08:12 AM

Tags for this Thread