View Single Post
Old 01-10-2012, 06:49 AM   #43
bogomil
Member
bogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterbogomil can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 21
Karma: 12650
Join Date: Apr 2011
Device: PB903
I am trying to introduce a new option -v for viewing a file in the tool but face the following problem: there are some characters after the end of the line - see below:


The code:

Code:
void choose_line(){
  int i=0,j=0;
  char* p=NULL;
	toc = (tocentry*)malloc(1024*sizeof(tocentry));
  
  FILE* pInFile = fopen (path, "rt");
  char strLine [1024]; // if your file has longer lines, make it bigger
  
  if (pInFile) {
    while ((p=fgets(strLine, sizeof (strLine), pInFile))) {
      
      // Remove trailing ' '
      for(;j<strlen(strLine) && p[j]==' ';j++) p+=1;
      
  		toc[i].level = 1;
  		toc[i].page = 0;
  		toc[i].position = i;
  		toc[i].text = strdup(p);

  		toc[i+1].level = 2;
  		toc[i+1].page = 0;
  		toc[i+1].position = i+1;
  		toc[i+1].text = strdup("next level");
  		i+=2;
    }
    fclose (pInFile);
    numfiles=i;
  }
  
	OpenContents(toc, i, 0, fileselect_handler);
}
Any ideas what is wrong?
Attached Files
File Type: zip main.c.zip (2.9 KB, 709 views)

Last edited by bogomil; 01-10-2012 at 06:52 AM.
bogomil is offline   Reply With Quote