Ok people.. this is getting aggravated, and, even though I'm sure it's something very stupid, I can't figure out why this string isn't getting printed.
The little piece of code is supposed to go through a string and remove the '/' character as well as the one right before. So if I have: "Free/d" as my sting, I'm supposed to end up with "Fred". Pretty Simple right?
Here's code (it's not much, I just wanted to make sure my idea was working)
Code:
#include <stdio.h>
#include <string.h>
int main () {
char string[30];
int i, j;
char temp[30];
strcpy (string, "Blee/ssee/d is tt/he man/.\n");
printf("%s\n", string);
for (i = j = 29; i >= 0; ) {
if (string[i] != '/') {
temp[j] = string[i];
printf("temp = %c, string = %c\n", temp[j], string[i]);
i--;
j--;
}
else
i = i-2;
}
printf("%s\n", string);
printf("%s\n", temp);
return;
}
My problem is when I run that, string is correct, but temp is blank, even though the printf statement in the for loop makes it print the correct stuff!!
Can anyone explain that to me?
I just tried something else, and temp prints by characters, but won't prints by string.
ie: %c works, %s doesn't!