I'm still pretty new to C, so please bear with me...
I am trying to read a file, parse it's contents and add html tags around each word. For example:
Code:
Text file contents...
This is a test
This is the next line
C program to convert to...
Code:
<tr>
<td>This</td> <td>is</td> <td>a</td> <td>test</td>
</tr>
<tr>
<td>This</td> <td>is</td> <td>the</td> <td>next</td> <td>line</td>
</tr>
I am a perl guy and I am writing a database application in C - mainly to learn the language. What I'm not sure of is what file io functions I should be using or which would be most efficient. Maybe I should be using some kind of pattern matching here like you would see in perl?
Here is my actual code - nothing new here, just file io...
Code:
while ( fscanf( fp, "%s", readline ) != EOF ){
if(match(readline,"\r")){ // silly attempt at regex
fprintf(cgiOut,"%s",readline);
}
}
I can't seem to find the carriage return using this method. Here is the "match" function that I found on the web - doesn't seem to function as the $var =~ // in perl.
Code:
int match(char *string, char *pattern){
int status;
regex_t re;
if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) {
return(0) ;
}
status = regexec(&re, string, (size_t) 0, NULL, 0);
regfree(&re);
if (status != 0) {
return(0) ;
}
return(1);
}
Please help, I'm pulling my hair out. If you're in the Dallas area, I'll buy you a beer!
Thanks,
Derek