int compress(char str[]) {
char tempStr [256];
int i,j, counter=0;
if (!isdigit(str[i]) && (!isspace(str[i]))) {
tempStr[j] = str[i];
j++;
printf("%c", tempStr[i]);
} else {
counter++;
}
str = tempStr;
}
char str[] = "abc abc abc 123";
result = compress(&str);
Question:
- how to assign a
strchartotempStr? - how to replace
strtotempStrin functioncompress? I thinkstr = tempStris wrong
thanks
1.Your code miss tempStr defination, like char tempStr[LENGTH], make sure LENGTH is big enough.
2.C string should be terminated by ‘\0’, so you need set tempStr[j] = ‘\0’ after the loop (which is missing I think). Then you can use strcpy copy tempStr to str.