C language

ARISTEIDIS MINAS aristeidism at usa.net
Mon Sep 6 13:41:25 EEST 1999


On SUN 05.Sep.99
Kostas Iliadis wrote.

> re paidia , 

> yparxei kamia synarthsh sth C i opoia na psaxnei ena
> string mesa se ena arxeio? Kati antoistoixo ths grep 
> dhladh 

> Eyxaristw

> NooB


 Stin Ansi C yparxei h synarthsh mesa sto 
<string.h> 
strstr(str1,str2) opoy psaxnei to string str2 mesa sto string str1 kai ean to
vrei epistrefei to ypoloipo toy str1 alliws epistrefei NULL.

px


#include <string.h>

char str1[255],str2[255];
char *res;
....
....
if((res=strstr(str1,str2))==NULL)
printf("NOT FOUND!\n");
else
printf ("OK  %s\n",res);


-----------------------------------------------------------------
Exw ftiaxei kai mia xeiropoihth synarthsh poy kanei thn idia doyleia

#include <string.h>

void left(char *s, int c);
char *findstr(char *str1, char *str2);

char str1[255],str2[255];
char strtemp[255];
char *res;
....
....

/*strcpy(strtemp,str1) 
 to str1 apothikeyetai mesa sto strtemp giati h synarthsh  findstr den krataei
      akaireo to string poy   tis dinoyme san orisma giayto sthn synarthsh
findstr den dinoyme to original   string str1 alla ena    proswrino */


if((res=findstr(str1,str2))==NULL)
printf("NOT FOUND!\n");
else
printf ("OK  %s\n",res);


.....
.....
/*************************************************/
void left(char *s,int c)
{
 if((c<=0) || (c>=(int)strlen(s))) return;
 *(s+c)='\0';
}
/************************************************/
char *findstr(char *str1, char *str2)
{
 int count1=strlen(str1);
 int count2=strlen(str2);
 int ejodos=0;
 char strtemp[255];
 do
 {
  count=strlen(str1);
  strcpy(strtemp,str1); 

  /* to str1 apothikeyetai mesa sto strtemp giati h synarthsh    left den
krataei       akaireo to string poy   tis dinoyme san orisma giayto sthn
synarthsh left den dinoyme to original   string str1 alla ena    proswrino */

  left(strtemp,count2);
  if(strcmp(strtemp,str2)==0) ejodos=2;
  if(!ejodos) if(count1>count2) str1++; else ejodos=1;
/* printf("%s -%s\n",strtemp,str2); */
 } while (!ejodos);
if (ejodos==2) return (str1);
else return NULL;
}


Kai stis dyo periptwseis to string str1 einai kathe grammi toy text file enw
to str2 einai to string poy theloyme na broyme.
Ean ektos apo thn eyresh toy str2 sto str1 theloyme na xrisimopoihsoyme kai me
allo tropo to str1
tote xrisimopoyme to proswrino strtemp stin findstr, kai stin strstr;

Opoiadhpote dieykrinhsh mporeis sto aristeidism at usa.net








____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1
--
====================================================================
Gia boithia (h na diagrafhte) e-mail sto majordomo at hellug.gr
Ta archives tis listas einai sto http://lists.hellug.gr/archives
prin steilete kapoia erothsh psakte mipos exei hdh apanththei.
Gia opoiodipote problima stilte e-mail ston owner-linux-greek-users at hellug.gr
====================================================================



More information about the Linux-greek-users mailing list