M
main()
Hi all,
I'm learning this great language called C.
I thought i would try my hand at writing small some code.
I wrote a very small function that takes two char pointers a and b.
It is to remove all letters from a that occurs in b.
#include <stdio.h>
void fun(char *a,const char *b)
{
int i=0,apos=0,j;
if(!a || !b) /* basic check*/
return;
for(;a;i++)
{
for(j=0; b[j] && a != b[j] ;j++); /*loop until end of b or until
a match is found*/
if(!b[j])
a[apos++] = a;
}
a[apos] = '\0';
}
int main(void)
{
char a[] = "hai how are you ?";
char b[] = "aeiou";
fun(a,b);
printf("%s\n",a);
return 0;
}
I have done and complied, it seems ok.
But i need your comment on my code.
I'm a newbie.I welcome any comment (like style, logic, any other neat
way to write the same function or proper usage etc).
Thanks for your time,
Yugi.
I'm learning this great language called C.
I thought i would try my hand at writing small some code.
I wrote a very small function that takes two char pointers a and b.
It is to remove all letters from a that occurs in b.
#include <stdio.h>
void fun(char *a,const char *b)
{
int i=0,apos=0,j;
if(!a || !b) /* basic check*/
return;
for(;a;i++)
{
for(j=0; b[j] && a != b[j] ;j++); /*loop until end of b or until
a match is found*/
if(!b[j])
a[apos++] = a;
}
a[apos] = '\0';
}
int main(void)
{
char a[] = "hai how are you ?";
char b[] = "aeiou";
fun(a,b);
printf("%s\n",a);
return 0;
}
I have done and complied, it seems ok.
But i need your comment on my code.
I'm a newbie.I welcome any comment (like style, logic, any other neat
way to write the same function or proper usage etc).
Thanks for your time,
Yugi.