Задание :
Дана строка символов. Удалить из строки все знаки препинания. Вывести исходную и преобразованные строки на экран.
вот мой код :
#include <stdio.h> #include <conio.h> #include <iostream.h> #include <string.h> #define slength strlen #include <STRLIB.cpp> void main() { char* c; char* s; int i; cout<<"Введите строку"; cin>>c; s=c; i=1; do { if (s[i]='.') sdelete(s,i,1); else ++i; } while (i>=slength(s)); cout<<"Новая строка "<<s<<endl; cout<<"Старая строка "<<c<<endl; getche(); }
А вот файл STRLIB.cpp , с функциями, который я подключаю :
#define slength strlen int spos(char *c, char *s); char *scopy( char *s, int k, int n); void sdelete(char *s, int k, int n); char* sinsert(const char *c, char *s, int k); char * strnorm(char *s); int spos(char *c, char *s) { char *ptr; ptr = strstr(s, c); return ptr-s; } char *scopy( char *s, int k, int n) { char *ptr=strdup(s); int i,j; for( i=0, j=k; i<n && s[i]!='\0'; i++,j++) ptr[i]=s[j]; ptr[i]='\0'; return ptr; } void sdelete(char *s, int k, int n) { for (int i=k,j=k+n; s[i]!='\0';i++,j++) s[i]=s[j]; } char* sinsert(const char *sc, char *sd, int k) { char *p=strdup(sd); strcat(p,sc); int i,j,lc=strlen(sc); for (i=0;i<k;i++) p[i]=sd[i]; for (j=0;j<lc;j++,i++) p[i]=sc[j]; for (j=k;sd[j]!='\0';i++,j++) p[i]=sd[j]; p[i]='\0'; return p; } char * strnorm(char *s) { char *p=strdup(s); int pos=spos(" ",p); cout<<"pos="<<pos<<endl; while (pos>=0) { sdelete(p,pos,1); pos=spos(" ",p); cout<<"pos="<<pos<<endl; } if (p[0]==' ') sdelete(p,0,1); if (p[slength(p)-1]!=' ') strcat(p," "); cout<<"p= |"<<p<<"|"<<endl; return p; } // end of strnorm
Подскажите, где у меня ошибка ?