Write a function that takes 2 inputs - A string and an integer flag (Value can be 0 or 1) • If the flag value is 'O' the function should return all the characters at even place in the input string • If the flag value is 'l'the function should return all the characters at odd place in the input string
Answers
Answered by
28
Please refer the attached image
Attachments:
Answered by
0
Answer:
#include <stdio.h>
#include <string.h>
int even_oddstr(char s[],int f)
{
char* p=s;
int i = 0;
int j = 0;
int k = 0;
char odd[21];
char even[21];
while (*p )
{
if (i % 2 == 0)
{
odd[j++] = *p;
} else
{
even[k++] = *p;
}
i++;
p++;
}
if(f==0){
printf("The even string is:%s\n ", even);
}
else
printf("The odd string is:%s\n ", odd);
return(1);
}
int main(void) {
char str[41];
int s,flag;
printf("Enter a string (40 characters maximum): ");
scanf("%s", &str);
printf("Enter the Flag Value 0 or 1");
scanf("%d",&flag);
s= even_oddstr(str,flag);
return 0;
}
Explanation:
- The function even_oddstr( ) will take 2 inputs - A string and an integer flag (Value is 0 or 1) •
- If the flag value is 'O' the function will return all the characters at even place in the input string •
- If the flag value is 'l' the function will return all the characters at odd place in the input string.
Similar questions