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?