0% found this document useful (0 votes)
8 views8 pages

He Ha

The document outlines a laboratory assignment for a Computer Programming course, focusing on string manipulation in C. It includes tasks for sorting names, validating usernames, and evaluating password strength, along with assessment rubrics and sample code for each task. The document also specifies the required apparatus and algorithms for the exercises.

Uploaded by

ponnapalliharish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

He Ha

The document outlines a laboratory assignment for a Computer Programming course, focusing on string manipulation in C. It includes tasks for sorting names, validating usernames, and evaluating password strength, along with assessment rubrics and sample code for each task. The document also specifies the required apparatus and algorithms for the exercises.

Uploaded by

ponnapalliharish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Department of Electronics and Communication Engineering

23CCE182 - Computer Programming Laboratory


STRINGS

Nam e of the Student HARISH PONNAPALLI

Registration Number CH.EN.U4CCE24010

Due date of
submission: Date of Submission:

Assessment Rubrics

Description Mark Allotted Mark


Secured
Aim and Problem analysis 20

Code and Algorithm 40

Experimental Result 30

Viva questions 10

Late Submission 10

Total Marks 100

Signature of Lab in-charge

1
Activity Sheet-5

STRINGS

AIM:
1.Write a c proggrame to sort list of names in alphabetical order.

2.Write a c programme to validate a username based on the following rules


a. User must have 6-15 characters
b. It only contains (a-z,A-Z,0-9)
c. Start with a letter.

3.Write a program to evaluate the strength of a password based on the following


criteria:
a. At least 8 characters long.
b.Contains at least one uppercase letter.
c.Contains at least one lowercase letter.
d.Contains at least one digit.
e.Contains at least one special character (!@#$%^&*).

PROGRAM ANALYSIS:
1. The program takes a list of names as input from the user and stores them in a
2D character array. It then sorts the names in alphabetical order using the
Bubble Sort algorithm, where each name is compared using the function, and
swapping is done using if necessary. After sorting, the program displays the
names in ascending order. The sorting process has a time complexity of O(n²),
making it efficient for small datasets but less optimal for larger lists. The
program effectively demonstrates string manipulation and sorting techniques in
C.

2.The provided C program validates a username based on three specific rules.


First, it checks if the length of the username is between 6 and 15 characters.
Second, it verifies that the username contains only alphanumeric characters
(letters and numbers). Lastly, the program ensures that the username starts with

2
an alphabetic character. If the username passes all these checks, it is considered
valid; otherwise, it is deemed invalid. The program uses the standard library
functions isalnum and isalpha to perform character validation efficiently. This
ensures the program meets all the required username validation conditions.

3. The program begins by reading the user’s input password. It first checks
whether the password is at least 8 characters long. Next, the program iterates
through each character to verify the presence of at least one uppercase letter,
one lowercase letter, one digit, and one special character from the set
(!@#$%^&*). If all these conditions are satisfied, the password is evaluated as
strong; otherwise, it is considered weak. This step-by-step analysis ensures that
all essential security criteria are met for robust password creation.

APPARTUS REQUIRED: Turbo C++

ALGORITHM:
a. Algorithm to Sort Names Alphabetically in C
b. Start
c. Take input for the number of names (N) from the user
d. Declare a 2D character array to store N names
e. Take input for each name and store it in the array
f. Use a sorting algorithm (Bubble Sort or any other)
g. Compare two adjacent names using strcmp()
h. If they are in the wrong order, swap them using strcpy()
i. Repeat until all names are sorted in alphabetical order
i. Display the sorted list of names
j. End

2.
a. Start the program.
b. Input: User enters John123.
c. Length check: strlen("John123") = 8 (valid, between 6 and 15 characters).
d. Character validation: J, o, h, n, 1, 2, 3 are all alphanumeric characters.
e. First character check: The first character J is a letter.

3
f. Since all conditions are satisfied, "Valid username" is printed.
g. End the program.

3.
a. start the program.
b. input the password from the user.
c. check if the password is at least 8 characters long.
d. if the password is shorter than 8 characters, output "weak password" and end
the program.
e. initialize flags for uppercase, lowercase, digit, and special character.
f. loop through each character in the password.
g. check if the character is an uppercase letter and update the uppercase flag if
true.
h. check if the character is a lowercase letter and update the lowercase flag if true.
i. check if the character is a digit and update the digit flag if true.
j. check if the character is one of the special characters (!@#$%^&*) and update
the special flag if true.
k. after processing all characters, verify that all flags are true.
l. if all flags are true, output "strong password"; otherwise, output "weak
password."
m. end the program.

CODE:
1.#include <stdio.h>

void sortNames(char names[][50], int n) {


char temp[50];
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
int k = 0;

4
while (names[i][k] == names[j][k] && names[i][k] != '\0' &&
names[j][k] != '\0') {
k++; }
if (names[i][k] > names[j][k]) {
for (int l = 0; l < 50; l++) {
temp[l] = names[i][l];
names[i][l] = names[j][l];
names[j][l] = temp[l];
} } } }}
int main() {
int n;
char names[10][50];
printf("Enter number of names (max 10): ");
scanf("%d", &n);
getchar(); // Consume newline character
printf("Enter names:\n");
for (int i = 0; i < n; i++) {
scanf("%s", names[i]);
}
sortNames(names, n);

printf("\nSorted names:\n");
for (int i = 0; i < n; i++) {
printf("%s\n", names[i]);
}
return 0;
}
2.
#include <stdio.h>
#include <ctype.h>
#include <string.h>

5
int isValidUsername(char *username) {
int length = strlen(username);
if (length < 6 || length > 15) {
return 0; }
if (!isalpha(username[0])) {
return 0; }
for (int i = 0; i < length; i++) {
if (!isalnum(username[i])) {
return 0;
}} return 1;}
int main() {
char username[20];
printf("Enter a username: ");
scanf("%s", username);
if (isValidUsername(username)) {
printf("Valid username!\n");
} else {
printf("Invalid username!\n");
} return 0;}

3. #include <stdio.h>
#include <string.h>
#include <ctype.h>
int strongPassword(char *password) {
int length = strlen(password);
int upper = 0, lower = 0, digit = 0, special = 0;
char specialCharacters[] = "!@#$%^&*";
if (length < 8) {
return 0;}
for (int i = 0; i < length; i++) {

6
if (isupper(password[i])) upper = 1;
if (islower(password[i])) lower = 1;
if (isdigit(password[i])) digit = 1;
if (strchr(specialCharacters, password[i])) special = 1; }
return upper && lower && digit && special;}
int main() {
char password[50];
printf("Enter a password: ");
scanf("%s", password);
if (strongPassword(password)) {
printf("Strong password!\n");
} else {
printf("Weak password!\n");
}
return 0;}
RESULTS:-
1.

2.

7
3.

You might also like