1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C Program Doubts

Discussion in 'C' started by abhiab1991, Sep 30, 2010.

  1. abhiab1991

    abhiab1991 New Member

    Joined:
    Sep 30, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    1) Write a program to count the number of blank spaces in a given string.
    2) Write a program to abbreviate a given string (e.g. if the input is Amar Akbar Anthony, the output will be AAA)
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    r u trying to put your homework on our shoulders?
    newayz..i can help u out...i m showing u how to do the first one then the second one u try out urself....

    1)

    Code:
    # include<stdio.h>
    # include<conio.h>
    # include<malloc.h>
    void main()
    {
    char *p;
    int count=0;
    clrscr();
    p=(char *)malloc(100*sizeof(char));
    
    gets(p);
    
    while(*p!='\0')
    {
    
    if(*p==' ')
    {
    count++;
    ++p;
    }
    else
    ++p;
    }
    printf("%d",count);
    }
    
     

Share This Page