While loops in C -


i tried changing do-while loop inside piece of code while loop. compiled code , ran didn't error messages, code did not print either, i'm assuming wrong while loop code. show me did wrong while loop code?

... while(fgets(transinput,sizeof(transinput),in)!=null){     i=0;      {             for(j=0;j<npos;j++){                 transchar = transinput[i];                 if(transchar != '\n' && transchar != '\0'){                     transtemp[j] = transchar;                     ++i;                 } else {                     transtemp[j] = ' ';                 }             }             for(ii=0;ii<npos;ii++){                 fprintf(out,"%c", transtemp[decrypt[ii]]);             }     }     while(transchar != '\n' && transchar != '\0');      fprintf(out,"\n"); } ... 

updated current code:

... i=0; while(fgets(input3,sizeof(input3),file1)!=null){ ch = input3[i];  while(ch != '\0' && ch!='\n'){     for(j=0;j<npos;j++){         //ch = input3[i];         if(ch != '\0' && ch!='\n'){             temp[j] = ch;             ++i;         } else {             temp[j] = ' ';         }       }      for(k=0;k<npos;k++){          fprintf(file2,"%c", temp[transposition[k]]);      } }  fprintf(file2,"\n");  } ... 

it looks i=0 got lost going do while while implementation.

even if i initialized 0 prior while loop, not reset after first iteration bug.

there issue j. set j 0 right after use in for loop.

for(j=0;j<npos;j++){     j=0; 

if npos less or equal zero, won't enter loop. if npos greater zero, never leave loop.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -