Thread: A little help, please

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    7

    A little help, please

    Hi everyone, I am new to the field of programming and I do not have much experience with C. Can you help me with solving the 2 requirements of my topic? Please very much.

    Requirement 1 - Uppercase
    The written program will have to correct each verse so that the first word starts with a capital letter, the rest of the alphabetical characters in the verse are lowercase.
    Example: It paSsEs thE SwAn on thE waTeR
    it becomes: It passes the swan on the water

    Requirement 2 - Trimming
    Identify sentences with unnatural spacing and remove this redundant whitespace, so that if there were more spaces between two consecutive words, now there will be only one. In some cases, in addition to eliminating redundant whitespace, all non-alphabetic characters are also removed:{'.', ',', ';', '!', '?', ':'}
    Example: It :.. passes ;;, the swan on .... ?? the .,, water
    it becomes: It passes the swan on the water
    Last edited by Vioooo; 11-24-2019 at 05:03 AM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  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
    Break the problem down into simpler achievable steps.

    This is your first program.
    Code:
    int main ( ) {
        char buff[100];
        while(fgets(buff,sizeof(buff),stdin)) {
            printf("%s",buff);
        }
    }
    Prove you can just read input and print it back out.

    This is your second program.
    Code:
    // Example: It paSsEs thE SwAn on thE waTeR
    // it becomes: It passes the swan on the water
    void Uppercase( char *buff ) {
        // Write your code here.
    }
    
    int main ( ) {
        char buff[] = "It paSsEs thE SwAn on thE waTeR\n";
        Uppercase(buff);
        printf("%s",buff);
    }
    Prove you can transform a given example.

    When (and only when) both work, you can merge them together like so.
    Code:
    // Example: It paSsEs thE SwAn on thE waTeR
    // it becomes: It passes the swan on the water
    void Uppercase( char *buff ) {
        // Write your code here.
    }
    
    int main ( ) {
        char buff[100];
        while(fgets(buff,sizeof(buff),stdin)) {
            Uppercase(buff);
            printf("%s",buff);
        }
    }
    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

Tags for this Thread