Jump to content
Sign in to follow this  
cmd

Ciclo For

Recommended Posts

cmd

Viva a todos,

Tenho o seguinte código em C:

{
//printf("i - %d\n\n",i);
if((i-n)<0)
{
 arr_aux[strlen(s)-(n-i)] = s[i];
}
else
{
 arr_aux[(n-i)] = s[i];
}
printf("----\n");
printf("i - %d\n\n",i);
}

Se eu comentar a linha do else, o ciclo executa bem, se deixar o código como está, os valores de i são:

----

i - 0

----

i - 1

----

i - 2

----

i - 1946157059

Alguém sabe porque isso se passa?


Cumps.cmd

Share this post


Link to post
Share on other sites
cmd

Consegui solucionar, trocando a linha do else de i-n para n-i:

arr_aux[(i-n)] = s;


Cumps.cmd

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.