Hello,
I've got a question how to change this function, because it should read
f.e. two lines:
33333n5rr door 3333is closed 3333333
n5rrr nanana tt4tt wall t6tt6t
then transform to:
nrr dooris closed
nrrr ttnananatt twallttwallt
(writing word instead of a digit was: nice ttt5555ttt //to: tttnicettt,deleting digits in first word and deleting alone digits)
here is
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
//-------------------Function--------------------------------------------
char AD(char *record, char *record_out)
{
char *p1 = record;
char *p2 = record_out;
while( *p1 )
{
// use temp pointer to locate
// end of digits
char* p3 = p1;
while( isdigit(*p3) )
p3++;
// is there a space following the digits ?
if( *p3 == ' ')
// yes, then skip the space and move on to the next char
p1 = p3+1;
else
{
// no, then was the last char put into temp buffer
// a space
if( *(p2-1) == ' ')
// yes, then overwrite that space with a new character
p2--;
p1 = p3;
}
// copy all characters up to the next digit
while(*p1 && !isdigit(*p1) )
*p2++ = *p1++;
}
}
//------------------------------------------------------------------------------
int main()
{
char *DELIMITERS = ".";
char *str,record[100],*o;
int len;
char line[]=" 33333n5rr door 3333is closed .n5rrr nanana tt4tt wall t6tt6t";
str = strtok(line, DELIMITERS);
char recordd[sizeof(record)] = {0};
while (str)
{
AD(str, recordd);
printf("%s\n",recordd);
str = strtok(NULL, DELIMITERS);
}
system("pause");
}