Untitled


SUBMITTED BY: antoineh1

DATE: June 3, 2016, 12:49 p.m.

FORMAT: Text only

SIZE: 813 Bytes

HITS: 517

  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(){
  4. char name[25];
  5. int numname = 0;
  6. char *ret;
  7. printf("Enter a series of names and type 'end' to stop:\n");
  8. do
  9. {
  10. scanf("%[^\n]", name );
  11. getchar();
  12. ret = strchr(name,' ');
  13. while (strlen(name) > 25 || ret != NULL) //Check if the name exceeds 25 characters.
  14. {
  15. printf("Name must not exceed 25 characters or contain blank characters:\n");
  16. printf("Enter a name again: \n");
  17. scanf("%[^\n]", name );
  18. getchar();
  19. ret = strchr(name,' ');
  20. }
  21. if (strlen(name) > 10) //Check if the name is more than 10 characters and count it.
  22. numname++;
  23. }
  24. while (strcmp(name,"end") != 0); //If name is 'end' then stop the program.
  25. printf("The number of names containing more than 10 characters is %d.",numname);
  26. return 0;
  27. }

comments powered by Disqus