Skip to content

Commit c478580

Browse files
committed
Convertion of string to ASCII and removal of a char from a string
1 parent a6a701d commit c478580

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Diff for: This is c code/45.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//To convert the string to its ASCII value
2+
#include <stdio.h>
3+
void main()
4+
{
5+
6+
char string[20];
7+
int n, count = 0;
8+
9+
printf("Enter the no of characters present in an array \n ");
10+
scanf("%d", &n);
11+
12+
printf(" Enter the string of %d characters \n" , n);
13+
scanf("%s", string);
14+
15+
while (count < n)
16+
{
17+
printf(" %c = %d\n", string[count], string[count] );
18+
++ count ;
19+
}
20+
21+
}

Diff for: This is c code/46.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//To remove a particular character from a given string
2+
#include <stdio.h>
3+
#include <string.h>
4+
void main() {
5+
char first[100], second[20];
6+
int i, j, fsl, ssl, temp, chk = 0;
7+
8+
printf("Enter the String: ");
9+
gets(first);
10+
11+
printf("Enter a Word: ");
12+
gets(second);
13+
14+
fsl = strlen(first);
15+
ssl = strlen(second);
16+
17+
for (i = 0; i < fsl; i++) {
18+
temp = i;
19+
for (j = 0; j < ssl; j++) {
20+
if (first[i] == second[j])
21+
i++;
22+
}
23+
chk = i - temp;
24+
if (chk == ssl) {
25+
i = temp;
26+
for (j = i; j < (fsl - ssl); j++)
27+
first[j] = first[j + ssl];
28+
fsl = fsl - ssl;
29+
first[j] = '\0';
30+
}
31+
}
32+
printf("\nNew String = %s", first);
33+
}

0 commit comments

Comments
 (0)