I am working with a pointer to an array of characters. This code is supposed to switch the cases of letters, delete digits, print two spaces instead of one, and print all other chars the same. It does all the rest fine except print other characters the same. This seems like it should be a non issue but I cannot figure it out. See anything that looks like its wrong?
void compareDuplicates(FILE * ifp, char mode){
/* size MAXCHARS+1 to hold full array + null terminate*/
char newArray [MAXCHARS +1] = {0};
char oldArray [MAXCHARS +1] = {0};
char * newStr = newArray;
char * oldStr = oldArray;
char * tempStr;
/* fill array, test for EOF*/
while(fgets(newStr,MAXCHARS, ifp)){
//if strings are the same, do not print anything
if(strcmp(newStr, oldStr) !=0){
//else print
testStrings(newStr);
}
//set oldStr pointer to newStr, set newStr pointer to oldStr reset newStr memory
//reset memory of newStr to all null chars
tempStr = oldStr;
oldStr = newStr;
newStr = tempStr;
memset(newStr,'\0',MAXCHARS);
}
}
void testStrings(char * array1){
int i = 0;
char c;
while(*(array1+i) != '\0'){
if(*(array1+i) >= 'A' && *(array1+i) <= 'Z'){
c = *(array1+i)+32;
printf("%c",c);
}
else if(*(array1+i) >= 'a' && *(array1+i) <='z'){
c = *(array1+i)-32;
printf("%c",c);
}
else if(*(array1+i) == ' '){
c = *(array1+i);
printf("%c",c);
printf("%c",c);
}
else if(*(array1+i) >= '0' || *(array1+i) <= '9'){
i++;
continue;
}
else{
c = *(array1+i);
printf("%c",c);
}
i++;
}
printf("\n");
}
for example, if given the lines:
CONSECUTIVE_LINE
CONSECUTIVE_LINE
CONSECUTIVE_LINE
123 REPEAT
123 REPEAT
232unique-line
the output will be:
consecutiveline
repeat
UNIQUELINE
representing a deletion of consecutive lines, the changing of cases, adding two spaces in the place of one and the deletion of digits. However, it will not print the normal underscores and other characters not targeted.