syntax - Simple C program - help needed -


i have c++ snippet:

#include <stdio.h> #include <string.h> int main(int argc, char *argv[]) {     char s[2048];     while (fgets(s, sizeof(s), stdin))     {         char *pos = strpbrk(s, ">\r\n");         if (pos != 0)         {             char *end = strrchr( pos, '<' );             if ( end )                 *end = '\0';             fputs(pos+1, stdout);         }          return 0;     }  } 

although when trimming text file using it, works 1 line e.g. trims 1 line only.

if try trim multiple lines e.g. file 30 lines in it, trims 1 line still. pretty confused, appreciated.

example text file:

report2011510222820.html:   <td width="60%" bgcolor="#ffffff" class="tablebody" valign="top">c:\users\admin\mon.bat</td> report2011510222820.html:   <td width="60%" bgcolor="#ffffff" class="tablebody" valign="top">c:\test123.bat</td> 

output:

c:\users\admin\mon.bat 

expected output:

c:\users\admin\mon.bat c:\test123.bat 

your return 0; inside while() loop exit after first run through loop. have move outside.

to add line break, replace

if ( end )     *end = '\0'; 

with

if ( end ) {     *end = '\n';     *(end + 1) = '\0'; } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -