0% found this document useful (0 votes)
8 views

strings programs

The document contains multiple C programs that perform string manipulations. These include inserting one string into another, deleting a specified number of characters from a string, searching for a substring within a string, and counting the number of characters and words in a string. Each program prompts the user for input and displays the results accordingly.

Uploaded by

alana.anasuri
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 views

strings programs

The document contains multiple C programs that perform string manipulations. These include inserting one string into another, deleting a specified number of characters from a string, searching for a substring within a string, and counting the number of characters and words in a string. Each program prompts the user for input and displays the results accordingly.

Uploaded by

alana.anasuri
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/ 5

#include<stdio.

h>

#include<string.h>

void main()

char str1[20], str2[20]; int len1, len2, n, i;

puts("Enter the string 1\n"); gets(str1);

len1 = strlen(str1);

puts("Enter the string 2\n"); gets(str2);

len2 = strlen(str2);

printf("Enter the position where the string is to be inserted\n"); scanf("%d", &n);

for(i = n; i < len1; i++)

str1[i + len2] = str1[i];

for(i = 0; i < len2; i++)

str1[n + i] = str2[i];

str2[len2 + 1] = '\0';

printf("After inserting the string is %s", str1);

#include<stdio.h>

#include<string.h>

void main()

{
char str[20];

int i, n, len, pos;

puts("Enter the string\n"); gets(str);

printf("Enter the position where the characters are to be deleted\n"); scanf("%d", &pos);

printf("Enter the number of characters to be deleted\n"); scanf("%d", &n);

len = strlen(str);

for(i = pos + n; i < len; i++)

str[i - n] = str[i];

str[i - n] = '\0';

printf("The string is %s", str);

#include<stdio.h>

#include<string.h>

void main()

char s[30], t[20]; char *found;

puts("Enter the first string: "); gets(s);

puts("Enter the string to be searched: "); gets(t);

found = strstr(s, t);

if(found)

{
printf("Second String is found in the First String at %d position.\n", found - s);

else

printf("-1");

##include<stdio.h>

#include <string.h>

void main()

char str[100];

int i = 0, l = 0, f = 1;

puts("Enter any string\n");

gets(str);

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

l = l + 1;

printf("The number of characters in the string are %d\n", l); for(i = 0; i <= l-1; i++)

if(str[i] == ' ')

f = f + 1;

}
}

printf("The number of words in the string are %d", f);

You might also like