Article View: nl.comp.programmeren
Article #647c++ isin code
From: TdC
Date: Thu, 10 May 2001 17:45
Date: Thu, 10 May 2001 17:45
64 lines
2509 bytes
2509 bytes
ik probeer deze code te laten werken in c++ in gewoon c werkt het maar wel
met warning bij compile
vb
bash-2.04$ gcc test.cpp
test.cpp: In function `int main()':
test.cpp:34: passing `char **' as argument 1 of `isin(char *, char *)'
bash-2.04$ cp test.cpp test.c
bash-2.04$ gcc test.c
test.c: In function `main':
test.c:34: warning: passing arg 1 of `isin' from incompatible pointer type
test.c:34: warning: passing arg 2 of `isin' from incompatible pointer type
bash-2.04$ ./a.out
it works
bash-2.04$
-------------------------- begin code -----------------------------
#include <stdio.h>
#include <string.h>
int isin(char *string1,char *string2) /* if (string1 isin string2) return 1
else return 0 */
{
char *word1;
word1 = strtok (string1, " "); // returns a char *
string2 = strstr (string2,word1); // returns a char * ///
if (string1 == '\0')
{
/*it isn't in it */
return 0;
}
if(strncmp (string1, string2, strlen(string1)) == 0)
{
/*its in it*/
return 1;
}
else
{
/*its not in it */
return 0;
}
}
int main()
{
char *a="test test";
char *b="lala test tetsttt123";
if (isin(&a,&b) == 1) // werkt in C niet in CPP en moet CPP zijn dus :(
{
printf("it works");
}
else
{
printf("it doesn't work");
}
return 0;
}
---------------- einde code -------------
alle hulp is welkom
alvast bedankt :)
Technical Details
Message-ID:
<GsAK6.67067$ii.8636438@afrodite.telenet-ops.be>Path:
arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!demon!diablo.netcom.net.uk!netcom.net.uk!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 107324,6e75983a23de8f69,start X-Google-Attributes: gid107324,public X-Google-Thread: fcea4,6e75983a23de8f69,start X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2001-05-10 10:46:26 PST Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!demon!diablo.netcom.net.uk!netcom.net.uk!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mail From: "TdC" <no#tdc@lomag.net#spam> Newsgroups: nl.comp.programmeren,be.comp.programming Subject: c++ isin code Lines: 67 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Message-ID: <GsAK6.67067$ii.8636438@afrodite.telenet-ops.be> Date: Thu, 10 May 2001 17:45:10 GMT NNTP-Posting-Host: 213.118.59.207 X-Complaints-To: abuse@pandora.be X-Trace: afrodite.telenet-ops.be 989516710 213.118.59.207 (Thu, 10 May 2001 19:45:10 MET DST) NNTP-Posting-Date: Thu, 10 May 2001 19:45:10 MET DST Organization: Telenet Internet