I've written a function to take spaces that i don't want out of a string.
that part of the function works.. however when i go to copy the new string into the old one it simply falls flat on its face.. any ideas would be very much appreciated!!!
Code:
void removeSpaces(char line[])
{
char newline[80] = {0};
int op = 0, opfin = 0;
int i = 0, j = 0, length = strlen(line);
/* remove any leading spaces and leave a space after the instruction*/
while(!opfin)
{
if(!isspace(line[i]) && isalpha(line[i]))
{
newline[j] = line[i];
op = 1;
j++;
}
else if(isspace(line[i]) && op)
{
newline[j] = ' ';
j++;
op = 0;
opfin = 1;
}
i++;
}
/* remove any spaces in the rest of the line */
while(line[i] != '\0')
{
if(!isspace(line[i]))
{
newline[j] = line[i];
j++;
}
i++;
}
newline[j] = '\0';
//strncpy(line, newline, strlen(newline));
length = strlen(newline);
i = 0;
while(i < length)
{
line[i] = newline[i];
i++;
}
}
As you can see i've tried strncpy and a while loop.. as well as strcpy and memcpy.
Thanks in advance
Rocco