Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5.  
  6. int main(void) {
  7. char buffer[100];
  8. char s[]={0};
  9. char ns[]={0};
  10. int l;
  11. int check;
  12. int i;
  13.  
  14. printf("Enter a string m80\n"); //getting input from user
  15.  
  16. fgets(buffer, sizeof(buffer),stdin);
  17. sscanf(buffer,"%s",&s);
  18. l=strlen(s);
  19.  
  20.  
  21. printf("Your string was %d characters long.\n", l); // prints the length of the string
  22.  
  23.  
  24.  
  25. for(i=0; i <= l ; i++ ) // if character is s is uppercase, make it lowercase else copy character from string to new string
  26. {
  27. if ( isupper(s[i]) )
  28. {
  29. ns[i]=tolower(s[i]);
  30. }
  31. else
  32. {
  33. ns[i]=s[i];
  34. }
  35. }
  36. check=strcmp(s, ns); //compares the two strings
  37.  
  38. if (check==0)
  39. {
  40. printf("String is lowercase\n");
  41. }
  42.  
  43. else if (check !=0)
  44. {
  45. printf("%s \n", ns); //if new string is the same as old, say string is lowercase, else print new string.
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement