Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views14 pages

Abid

Dhaka

Uploaded by

738t1p9vrj
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)
5 views14 pages

Abid

Dhaka

Uploaded by

738t1p9vrj
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/ 14

Abid Mia

ID : 41250102714

MD :assessment
Lab ASIB String

ID : 41250102594
​ ​ ​ ​ ​ Lab assessment String
Task: 01

#include <stdio.h>
#include <string.h>

int main()
{
char str[]="My name is andy";
int i=0 ,len=0;
while(str[i]!='\0')
{
i++;
len++;
}
printf("%d\n",len);
return 0;
}

Task : 02

#include <stdio.h>
#include <stdlib.h>

int main()
{
char str1[]="My name";
char str2[]="is andy";
char str3[30];
int i=0, j=0 ;
while(str1[i]!='\0')
{
str3[i]=str1[i];
i++;
}
while(str2[j]!='\0')
{
str3[i]=str2[j];
j++;
i++;
}
printf("%s\n",str3);
return 0;
}

Task: 03

#include <stdio.h>
#include <stdlib.h>

int main()
{
char str[]="My name is andy";
char ch ;
int i=0 ,vowel=0;
while((ch=str[i])!='\0')
{
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||
ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'
)
vowel++;
i++;
}
printf("%d\n",vowel);
return 0;
}

Task : 04

#include <stdio.h>
#include <stdlib.h>

int main()
{
char str[]="My name is Asib";
char ch;
int i =0 , word = 0 ;
while((ch=str[i])!='\0')
{
if(ch==' ')
word++;
i++;
}
word++;
printf("%d\n",word);
return 0;
}

Task : 05

#include <stdio.h>
#include <string.h>

int main()
{
char str[]="My name is Asib";

strrev(str);
printf("%s\n",str);

return 0;
}

Task : 06

#include <stdio.h>
#include <string.h>

int main()
{
char str[]="My name is asib";
strupr(str);
printf("%s\n",str);
return 0;
}

Task : 07

#include <stdio.h>

#include <ctype.h>

int main() {

char str[100];
int main() {

char str[100];

int i;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin);

for (i = 0; str[i] != '\0'; i++) {

if (islower(str[i])) {

str[i] = toupper(str[i]);

} else if (isupper(str[i])) {

str[i] = tolower(str[i]);

printf("Toggled string: %s", str);

return 0;

Task : 08

#include <stdio.h>

#include <string.h>

int main() {

char str[100], temp;

int i, j, len;

printf("Enter a string: ");


fgets(str, sizeof(str), stdin);

str[strcspn(str, "\n")] = '\0';

len = strlen(str);

for (i = 0; i < len - 1; i++) {

for (j = i + 1; j < len; j++) {

if (str[i] == ' ' || str[j] == ' ')

continue;

if (str[i] > str[j]) {

temp = str[i];

str[i] = str[j];

str[j] = temp;

printf("Sorted string: %s\n", str);

return 0;

Task : 09

#include <stdio.h>

#include <string.h>
int main()

char str[]="Welcome to cse everyone";

char ch ;

printf("Enter your search character :");

scanf("%c",&ch);

int i =0 ;

int count=0;

while(str[i]!='\0')

if(ch==str[i]){

count++;

i++;

printf("%d",count);

return 0;

Task : 10

#include <stdio.h>

#include <string.h>
int main()

char str[15]="madam";

char str1[15];

int i = 0, j,len= 0 ;

while(str[i]!='\0')

i++;

len++;

for(j=0,i=len-1; i>=0; i--,j++)

str1[j]=str[i];

printf("str : %s\n",str);

printf(" str1 : %s\n",str1);

int d ;

d = strcmp(str,str1);

if(d==0)

printf("yes");

else
printf("no");

return 0;

Task : 11

#include <stdio.h>

#include <string.h>

int main()

char str[]="I am 21 years old" , ch;

int i =0 ,digit = 0 ;

while((ch=str[i])!='\0')

if(ch>='0' && ch<='9')

digit++;

i++;

printf("%d\n",digit);
return 0;

Task : 12

#include <stdio.h>

#include <string.h>

#include <ctype.h>

void toLowerCase(char *str) {

for (int i = 0; str[i]; i++) {

str[i] = tolower(str[i]);

int main() {

char str[200], word[50];

char tempStr[200];

int count = 0;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin);

str[strcspn(str, "\n")] = '\0'; // remove newline

printf("Enter a word to count: ");

fgets(word, sizeof(word), stdin);

word[strcspn(word, "\n")] = '\0’ ;


strcpy(tempStr, str);

toLowerCase(tempStr);

toLowerCase(word);

char *token = strtok(tempStr, " ,.!?;:\"'\t\n");

while (token != NULL) {

if (strcmp(token, word) == 0) {

count++;

token = strtok(NULL, " ,.!?;:\"'\t\n");

printf("The word \"%s\" occurs %d time(s).\n", word, count);

return 0;

Task : 13

#include <stdio.h>

#include <string.h>

int main() {

char str[200];

int i, j, k;
int len;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin);

str[strcspn(str, "\n")] = '\0';

len = strlen(str);

for (i = 0; i < len; i++) {

for (j = i + 1; j < len; ) {

if (str[i] == str[j]) {

for (k = j; k < len; k++) {

str[k] = str[k + 1];

len--;

} else {

j++;

printf("String after removing duplicates: %s\n", str);

return 0;

}
Task : 14

#include <stdio.h>

#include <string.h>

int main() {

char str[200];

int freq[256] = {0};

int i, max = 0;

char maxChar;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin);

str[strcspn(str, "\n")] = '\0';

for (i = 0; str[i] != '\0'; i++) {

if (str[i] != ' ' && str[i] != '\t' && str[i] != '\n') {

freq[(unsigned char)str[i]]++;

for (i = 0; i < 256; i++) {

if (freq[i] > max) {

max = freq[i];

maxChar = (char)i;
}

printf("The maximum occurring character is '%c' (appears %d times).\n",


maxChar, max);

return 0;

Task : 15

#include <stdio.h>

#include <string.h>

int main() {

char str[200];

char words[50][50];

int i = 0, j = 0, k = 0;

int wordCount = 0;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin);

str[strcspn(str, "\n")] = '\0';


for (i = 0; str[i] != '\0'; i++) {

if (str[i] != ' ') {

words[wordCount][j++] = str[i];

} else {

words[wordCount][j] = '\0'; // end of word

wordCount++;

j = 0;

words[wordCount][j] = '\0';

wordCount++;

printf("Reversed string: ");

for (i = wordCount - 1; i >= 0; i--) {

printf("%s", words[i]);

if (i > 0) printf(" ");

printf("\n");

return 0;

You might also like