Only part of the code executing
Code:
int main() Code:
enter de string |
Is this legal syntax?
Code:
for(j=k-1;j=0;j--) |
why.? what is wrong with this code.? j starts from say 5 n decrements every time.
|
Quote:
I'd probably avoid replying to threads if you're not sure you can help, so you don't remove them from the zero reply list. |
Quote:
|
To start:
Code:
old: for(j=k-1;j=0;j--) |
Quote:
You have other issues with your code as well that you need to look at, but I figured I would point out the first problem and let you figure out the rest. |
Quote:
Code:
int main() Code:
|
How did those extra 2 characters(junk ) get added to str2, also I'm getting this error
warning: comparison between pointer and integer in the strcmp fn line |
Insert this line before/after the cycle: str2[k]= '\0'
PS: strcmp returns a number, not a pointer, so use ==0, not ==NULL |
I replaced NULL with 0 and the warning disappeared but still not getting the desired result
Code:
enter de string |
Insert this line before/after the cycle: str2[k]= '\0'
|
Quote:
But could you please explain how those junk characters are formed.? I'm only able to figure out the occurence of first junk character which is because of i++ statement. How is it that the other one occurs.? |
This thing is called memory garbage. What you have to remember is adding a terminating zero to the end of a string you create manually. (Strings created by library functions (strcpy, strcat, sprintf, getenv etc) are already zero-terminated.)
|
Quote:
So this problem, is it caused because of my str2[i++] statement or is it because of something else.? |
All times are GMT -5. The time now is 03:21 AM. |