Question: The following C function should take two strings, and return characters that occur in both strings, without duplicates, and in the order they appear in
The following C function should take two strings, and return characters that occur in both strings, without duplicates, and in the order they appear in the first string but doesn't work as it should. Are you able to see the problem?
inter.c
#include
#include
char mystrchrchar str char c
while str
if str c
return str;
if str
return ;
return ;
char mystrnchrconst char str const char c sizet sz
char strtmp ;
while sz
if str c
strtmp char str;
break;
str;
return strtmp;
char interchar str char str
char str charmallocsizeofcharsizeofstr sizeofstr;
sizet sz ;
char pstr;
while pstrstr
ifmystrnchrstr pstr sz
continue;
ifmystrchrstr pstr
strsz pstr;
return str;
int main
char test;
test interpadinton "paqefwtdjetyiytjneytjoeyjnejeyj"; "padinto"
test interddfvewgf "gtwthgdwthdwfteewhrtaghffdhsd; dfewg
printfResult: s
test;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
