Activity 3 - Take Home (C Libraries) - PEREZ
Activity 3 - Take Home (C Libraries) - PEREZ
Direction:
A. First, read this site and familiarize each function available in the library.
string.h
ctype.h
stdlib.h
B. Create a program as directed in the problem. Provide the code in the box.
Problems:
#include <string.h>
int main() {
char words[5][100];
char temp[100];
printf("Enter 5 words:\n");
scanf("%s", words[i]);
strcpy(temp, words[i]);
strcpy(words[i], words[j]);
strcpy(words[j], temp);
printf("\nSorted words:\n");
printf("%s\n", words[i]);
return 0;
}
2. Create a program that check if a password is strong or not. A strong
password contains at least 1 uppercase, no space, 3 digits, and length is 8
above.
Example:
Password: abcdE123x
Strong password!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char password[100];
scanf("%s", password);
length = strlen(password);
if (isupper(password[i])) {
hasUppercase = 1;
if (isdigit(password[i])) {
digitCount++;
if (isspace(password[i])) {
hasSpace = 1;
printf("Strong password!\n");
} else {
printf("Weak password! A strong password has atleast 1 uppercase letter, 3 digits, no spaces, and is 8 characters or more.\n");
return 0;
3. Create a program that adds all the digit that can be found in a string
inputted by the user.
Example:
Enter String: 1 little 2 little 3 little Indians, 4 little 5 little 7 little Indians
Sum of all found digits: 22
#include <stdio.h>
#include <string.h>