Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- int main(void) {
- char buffer[100];
- char s[]={0};
- char ns[]={0};
- int l;
- int check;
- int i;
- printf("Enter a string m80\n"); //getting input from user
- fgets(buffer, sizeof(buffer),stdin);
- sscanf(buffer,"%s",&s);
- l=strlen(s);
- printf("Your string was %d characters long.\n", l); // prints the length of the string
- for(i=0; i <= l ; i++ ) // if character is s is uppercase, make it lowercase else copy character from string to new string
- {
- if ( isupper(s[i]) )
- {
- ns[i]=tolower(s[i]);
- }
- else
- {
- ns[i]=s[i];
- }
- }
- check=strcmp(s, ns); //compares the two strings
- if (check==0)
- {
- printf("String is lowercase\n");
- }
- else if (check !=0)
- {
- printf("%s \n", ns); //if new string is the same as old, say string is lowercase, else print new string.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement