#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    String manipulation


    Hey guys,

    I wrote the following code so far(at the very bottom), which asks the user to input a string less than 100 characters such as "Programming's Hard!"

    I am trying to get it so that the program will be able to restate the string that the user entered above, but do three things differently:
    1) switch it to all capital letters if its not already in capital,
    2) remove any spaces that may be in the string
    3) remove any no alphabetic symbols (i.e. '!')

    the output should look like this:

    Enter String: Programming's Hard!

    String to Encode: PROGRAMMINGSHARD



    If you guys could help me understand how to do any of the three things, i would really appreciate it, i am really lost as to how to go about it.

    thanks!

    Code:
    #include <stdio.h>
    #include <string.h>
    
    //Define all Variables
    char string[100];
    int count;      
    
    // Prompt User to Enter String
    
    int array[27]= {0b0001,0b001111,0b10110,0b00000,0b011,0b11011,0b001100,0b1001,0b0100,
                    0b11001011,0b1100100,0b00001,0b11000,0b0101,0b0010,0b001110,0b1100101000,0b1010,
                    0b1000,0b111,0b10111,0b110011,0b11010,0b1100101001,0b001101,0b1100101010,0b1100101011};
    int main() {
    
    do{
    
    printf("Enter String: ");
    scanf("%s", string);
    
    for(count=0; count<=strlen(string); count++) { 
       if(string[count]>97 && string[count] >= 122)
          string[count]=string[count]-32;
    }
    
    printf(" String to Encode: %s", string);
    
    }
    while(strcmp(string, "quit")); 
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,413
    Rep Power
    1871
    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

IMN logo majestic logo threadwatch logo seochat tools logo