Aim: Program 1
Aim: Program 1
Program 1
int main ()
{
char str[100], word[100], new[10][30];
int i=0, j=0, k=0, len1=0, len2=0, l=0;
new[k][j] = '\0';
j = 0;
for(i=0;i<k;i++)
{
int present = 0;
for(l=1;l<k+1;l++)
{
if(new[l][j]=='\0' || l==i)
{
continue;
}
if(strcmp(new[i],new[l])==0)
{
new[l][j] = '\0';
present = present + 1;
}
}
j = 0;
for(i=0;i<k+1;i++)
{
if(new[i][j]=='\0')
continue;
else
printf("%s ",new[i]);
}
printf("\n");
return 0;
}
RESULT:
OUTPUT:
Welcome to C Programming Class, again!
Program 2
PROBLEM Write a program to find and replace a particular word from the string.
STATEMENT:
ALGORITHM: 1. Declare character arrays for input string, word to find and word to
replace
2. Ask the user to input string
3. Read string along with whitespaces
4. Ask user to input word to find
5. Read the word to find
6. Ask user to input word to replace
7. Read word to replace
PROGRAM: #include<stdio.h>
#include <string.h>
#include<stdbool.h>
int main()
{
char str[100], find[100], replace[100];
int i = 0;
while(ptr[i] != NULL)
{
i++;
ptr[i] = strtok(NULL, del);
}
i = 0;
while(ptr[i] != NULL)
{
if(*ptr[i] == *find)
{
ptr[i] = replace;
}
printf("%s ", ptr[i]);
i++;
}
}
RESULT: