#include #include #include int grammes; typedef struct typos_seiras { int mikos; char xaraktiras[80]; }typos_seiras; void dimiourgia(typos_seiras *seira) { seira->mikos = 0; } int mikos(typos_seiras seira) { return seira.mikos; } char anaktisi(typos_seiras seira, int i) { if (i >= 0 && i < mikos(seira)) { return seira.xaraktiras[i]; } else printf("Deiktis ektos diastimatos"); return '0'; } void prosartisi(typos_seiras *seira, char xar) { if (mikos(*seira) == 80) { printf("H symvoloseira einai gemati"); getchar();} else seira->mikos++; seira->xaraktiras[seira->mikos - 1] = xar; } void diagrafi(typos_seiras *seira) { int i; if (mikos(*seira) == 0) printf("Keni symvoloseira"); else { for (i = 0; i <= (seira->mikos - 2); i++) seira->xaraktiras[i] = seira->xaraktiras[i + 1]; seira->mikos--; } } int anazitisi_seiras(typos_seiras sxima, typos_seiras keimeno) { int s, k, thesi, mkss=mikos(sxima), mksk=mikos(keimeno); if (mkss == 0) return -1; else if (mkss > mksk) return -2; else { thesi = 0; s = 0; k = 0; while ((s < mkss) && (k < mksk) && anaktisi(sxima,s)!='\0'){ if (anaktisi(sxima, s) == anaktisi(keimeno, k)) { s++; k++; } else { thesi++; k = thesi; s = 0; } } if ((s > mkss - 1) || ((anaktisi(sxima,s))=='\0')) return thesi; else return -2; } } void antigrafi_seiras(typos_seiras arxiki, int thesi, int n, typos_seiras *neaseira) { int i; if (n >= 80) printf("H nea seira einai poly megali."); else { // dimiourgia(neaseira); for (i = 0; i < n; i++) prosartisi(neaseira, anaktisi(arxiki, thesi + i)); } } void synenosi_seiras(typos_seiras seira1, typos_seiras seira2, typos_seiras *neaseira) { int mks1=mikos(seira1), mks2=mikos(seira2); if (mks1 + mks2 >= 80) printf("Oi symvoloseires einai megales kai den mporoun na synenwthoyn."); else { dimiourgia(neaseira); antigrafi_seiras(seira1, 0, mks1-1, neaseira); antigrafi_seiras(seira2, 0, mks2-1, neaseira); } } void eisagogi_seiras(typos_seiras seira1, typos_seiras *seira2, int thesi) { typos_seiras proti, teleytaia; dimiourgia(&proti); dimiourgia(&teleytaia); // if ((thesi>=0) && (thesi < mikos(*seira2))) { antigrafi_seiras(*seira2, 0, thesi, &proti); antigrafi_seiras(*seira2, thesi, mikos(*seira2)-thesi, &teleytaia); synenosi_seiras(proti, seira1, &proti); synenosi_seiras(proti, teleytaia, seira2); } else printf("Den einai swsti i timi tis %d", thesi); } void diagrafi_seiras(typos_seiras *seira, int thesi, int mks) { typos_seiras proti, teleytaia; dimiourgia(&proti); dimiourgia(&teleytaia); // int a=thesi+mks; // if ((thesi>0) && (a <= mikos(*seira)-thesi)) // { antigrafi_seiras(*seira, 0, thesi, &proti); thesi += mks; antigrafi_seiras(*seira, thesi, mikos(*seira)-thesi, &teleytaia); synenosi_seiras(proti, teleytaia, seira); // } // else // printf("H timi tis %d einai arnitiki h poly megali.den mporei na ginei i diagrafi.", thesi); } void antikatastasi_seiras(typos_seiras seira1, typos_seiras seira2, typos_seiras *seira) { int thesi=anazitisi_seiras(seira1,*seira),mks; printf("\n%d\n",thesi); if (thesi >=0) { mks = mikos(seira1); diagrafi_seiras(seira, thesi, mks); eisagogi_seiras(seira2, seira, thesi); } } void typose_seira(typos_seiras seira) { int i, mks = mikos(seira); for (i = 0; i < mks - 1; i++) putchar(anaktisi(seira, i)); } void add() { FILE *eis,*ex; typos_seiras seira,grammi; int n,i,j,k; char xar; system("cls"); printf("Dwste arithmo grammis poy tha prostethei i symvoloseira:"); scanf("%d",&n); getchar(); printf("Dwste ti symvoloseira:(katw apo 80 xaraktires)"); dimiourgia(&seira); scanf("%c",&xar); while(xar!='\n') { prosartisi(&seira,xar); scanf("%c",&xar); } //prosartisi(&seira,'\0'); //anoigei_ta_arxeia(eis,eks); if ((eis = fopen("koligas.txt", "r"))==NULL) { fprintf(stderr, "Lathos sto anoigma toy koligas.txt"); exit(-1); } if ((ex = fopen("neo.txt", "w"))==NULL) { fprintf(stderr, "Lathos sto anoigma toy neo.txt"); exit(-1); } for(i=0;i=0) { antikatastasi_seiras(palia,nea,&seira); //printf("\nginetai antikatastasi\n"); /*for(j=k,o=0;j