i wrote this and it compiles with no errors or warnings. Works too, but having some small problems.
1) It segfaults at the very end after executing the last printf and calling fclose.
2) It lists the number of bites as 9 - even thought the filesize is greater than that.
3) why isnt it displayed in binary as that is how im reading the file
here is the code
Code:
#include <stdio.h>
int main (int argc, char *argv[]){
FILE *p = fopen(argv[1],"rb");
char buff[256];
int i = 0;
int bytes = 0;
while(1){
bytes = fread(buff,sizeof(buff),256,p);
printf("Packet %d :\nDump: %s\n\n",i,buff);
i++;
if(feof(p))
break;
}
printf("Finished Reading From file.\n Total Bytes : %d\n",bytes);
//prints out printf then segfaults.
fclose(p);
return 0;
}
OUTPUT:
Code:
brian@brian-unix-box:~/c$ ./read writers.php
Packet 0 :
Dump: <?PHP
SESSION_START();
//Writers.php
//
include 'includes/top.php';
include 'includes/header.php';
include 'functions.php';
include 'conf.php';
include 'opendb.php';
echo "<div class = 'writersmain'>";
//should display like following
//name of writer as link to profile
//threads that they have started
//div to css
//adb
//adbtName
//adbhdr
if(isset($_GET['id'])){
$r = protect($_GET['id']);
$val2 = "SELECT * FROM tbl_article WHERE pID = " .$r;
$res2 = mysql_query($val2) or die (mysql_error());
if(mysql_num_rows($res2) < 1){
echo "<div class = 'adb'><div class = 'adbtName'>This user has no Articles</div></div>";
}
else{
$nq = "SELECT * FROM tbl_users WHERE USERID = " .$r;
$resnq = mysql_query($nq) or die (mysql_error());
$arrnq = mysql_fetch_array($resnq);
echo "<div class = 'adbhdr'>All Articles Posted By: ".$arrnq['uname']."</div>";
while($row2 = mysql_fetch_array($res2,MYSQL_ASSOC)){
echo "<div class = 'adb'>
<div class = 'adbtName'>
<a href = 'articles.php?id=" .$row2['ArticleID']."'>
".$row2['ArticleTitle']."</a></div>
</div>";}
}
}
else{
echo "<h3>Search For Short Stories, Rants and Reviews By Author</h3>";
$val = "SELECT * FROM tbl_users";
$res = mysql_query($val) or die (mysql_error());
echo "<form action = 'writers.php' method = 'GET'><SELECT NAME = 'id'>";
while($row = mysql_fetch_array($res,MYSQL_ASSOC)){
echo "<option value = '".$row['USERID']."'>".$row['uname'];
/*echo "<div class = 'adbhdr'>".$row['uname']."</div>";
$val2 = "SELECT * FROM tbl_article WHERE pID = " .$row['USERID'];
$res2 = mysql_query($val2) or die (mysql_error());
if(mysql_num_rows($res2) < 1){
echo "<div class = 'adb'><div class = 'adbtName'>This user has no Articles</div></div>";
}
else{
while($row2 = mysql_fetch_array($res2,MYSQL_ASSOC)){
echo "<div class = 'adb'>
<div class = 'adbtName'>
<a href = 'articles.php?id=" .$row2['ArticleID']."'>
".$row2['ArticleTitle']."</a></div>
</div>";}
}*/
}
echo "</SELECT>";
echo "<input type = 'submit'value = 'Get Articles'></form>";
}
echo '</div>'; //ending cc di
include 'includes/footer.php';
?>
Finished Reading From file.
Total Bytes : 9
Segmentation fault
brian@brian-unix-box:~/c$ ./read writers.php