C
c_beginner
Dear group,
I want to implement a solution to the following link:
http://acmicpc-live-archive.uva.es/nuevoportal/data/p2006.pdf
As a beginning I am trying to implement this little sample program which
will
delete the repeated strings in two set of strings.
The code:
#include<stdio.h>
#include<stdlib.h>
enum str_match{UN_MATCHED=-1,MATCHED};
unsigned my_strmatch(const char *pattern1,char *pattern2)
{
while(pattern1 != '\0' && pattern2++ != '\0')
if( pattern1 == pattern2)
return MATCHED;
else
return UN_MATCHED;
}
int main(void)
{
char *str1 = "grammer is a important for a language isn't it";
char *str2 = "grammer is a dufficult in a language isn't it";
while(str1 != '\0' && str2 != '\0')
{
if(my_strmatch(str1,str2) == MATCHED)
free(str1);
}
printf("the remaining string are %s",str1);
return 0;
}
I know that I am making a very basic error in pointer memory allocation
which
I am not sure. Can any one help me out in doing this. Don't just write the
program
since that will be too simple for you people. Just give me a hint. Thanks.
I want to implement a solution to the following link:
http://acmicpc-live-archive.uva.es/nuevoportal/data/p2006.pdf
As a beginning I am trying to implement this little sample program which
will
delete the repeated strings in two set of strings.
The code:
#include<stdio.h>
#include<stdlib.h>
enum str_match{UN_MATCHED=-1,MATCHED};
unsigned my_strmatch(const char *pattern1,char *pattern2)
{
while(pattern1 != '\0' && pattern2++ != '\0')
if( pattern1 == pattern2)
return MATCHED;
else
return UN_MATCHED;
}
int main(void)
{
char *str1 = "grammer is a important for a language isn't it";
char *str2 = "grammer is a dufficult in a language isn't it";
while(str1 != '\0' && str2 != '\0')
{
if(my_strmatch(str1,str2) == MATCHED)
free(str1);
}
printf("the remaining string are %s",str1);
return 0;
}
I know that I am making a very basic error in pointer memory allocation
which
I am not sure. Can any one help me out in doing this. Don't just write the
program
since that will be too simple for you people. Just give me a hint. Thanks.