Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <values.h>
- #include <string.h>
- int get_min_length_of_world(char *string);
- void change_register(char *string);
- void add_space(char *string);
- const int N = 200;
- int main() {
- char *string = malloc(N*sizeof(char));
- printf("Enter the string: ");
- fgets(string, N, stdin);
- printf("%d\n", get_min_length_of_world(string));
- change_register(string);
- add_space(string);
- printf("%s", string);
- return 0;
- }
- int get_min_length_of_world(char *string){
- int min_length = INT_MAX;
- char *firstletter = string;
- char *lastletter = NULL;
- for (char *letter = string; *letter!='\0'; letter++){
- if (*letter == ' ' || *letter == '\n'){
- lastletter = letter;
- if (lastletter-firstletter < min_length)
- min_length = lastletter - firstletter;
- firstletter = letter+1;
- }
- }
- return min_length;
- }
- void add_space(char *string){
- char *new_string = malloc(N*sizeof(char));
- for (char *letter = string; *letter!='\0'; letter++){
- char tmp[2] = {*letter, '\0'};
- strcat(new_string, tmp);
- if (*letter == ' '){
- strcat(new_string, " ");
- letter+=1;
- }
- }
- strcpy(string, new_string);
- free(new_string);
- }
- void change_register(char *string){
- for (char *letter = string; *letter!=' '; letter++){
- if (*letter>='a' && *letter<='z'){
- *letter-=' ';
- }else{
- if (*letter>='A' && *letter<='Z'){
- *letter+=' ';
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement