Professional Documents
Culture Documents
h>
#include<string.h>
#include<conio.h>
int main()
{
char str1[80],str2[80];
int skip, counter, i;
printf("Please enter the first string\n");
scanf("%80s",str1); //scanning the strings
printf("Please enter the second string\n");
scanf("%80s",str2);
printf("Please enter a skip\n");
scanf("%d",&skip);
for(i=1;i<=skip;i++) //running over the function, #skip times
{
counter=skip_strstr (str1,str2,i);
printf("The second string was %d times in skip #%d.\n",counter,i);
}
return 0;
}
Output:
Please enter the first string
abcacbacbabcaccbbbacbac
Please enter the second string
ab
Please enter a skip
3
The second string was 2 times in skip #1.
The second string was 3 times in skip #2.
The second string was 1 times in skip #3.
#include <stdio.h>
#include <string.h>
void eraseDuplicates(char* str,char c)
{
int i=0,*j, *k;
for (i=0;str[i]!='\0';i++)
{
if (str[i]==c && str[i+1]==c)
{
for (j=&i;*j!=c;j++)
{
for(k=*j;*k='\0';k++)
{
str[*k]=str[*k+1];
}
}
}
}
int main()
{
int i;
char str[]="abcaaabcaabad";
char c;
printf("please enter the letter you want to erase\n");
scanf("%c", &c);
eraseDuplicates(str, c);
for (i=0;str[i]!='\0';i++)
printf("%s", str[i]);
return 0;
}
OUTPUT
please enter the letter you want to erase
abcabcabad