#c language strings inverse the word of a sentence

1 messages · Page 1 of 1 (latest)

cosmic burrow
#

thise program

#

isnt working idk why

#

or what i did wrong either

#

i traced it and it worked for me

#

but its not working on a compiler

#

if input "way more" it should give me "more way"

austere moth
#

your variables names are really bad lol, can you give them more meaningful name? xD I dont know what your code is doing, also not sure how you traced it but you code goes into an infinite loop in the second while and crash there

#
while (S[j] != '\0' || j != 0) {
            j--;
        }


#

it just loop infinitely there

#

what is that while looking for? it seems pointless

#

isnt that just to set j to 0?

cosmic burrow
#

didnt know it goes to infinity

#

i thought it will just stop at j=0

#

ill change variables now this is how i learned at school

#

So ill change to them to more clear ones

#

oh OH now i noticed what did u mean by it goes infinitely

austere moth
#

You probably meant && instead of ||

cosmic burrow
# austere moth your variables names are really bad lol, can you give them more meaningful name?...

so the program is supposed to give me the sentence in a reverse order.
so all i tried to do without using string.h library i got the length of the stringth by

                 i++;``` 
and then i got the length of the string or sentence given by user and got another counter `j` that will count where each word starts in reverse so j will start at ```j=i-1```
and the while its supposed to count till the first space in reverse 
```while(s[j]!=' ' || j!=0)
             j--;
#

oh

#

And yesbits supposed to b &&

#

instead of or

#

this im still not used to is

#

ill just try it now again because i had 2 mistakes the \0 and ||

#

AND thank u it finally worked