Bellow is the piece of code that causes Segmentation Fault:
(in Linux Segmentation Fault is usually due to illegal memory access)
else if(intData==3)
{
FILE *fp;
int ch;
if((fp = fopen("file.txt","rb"))==NULL) {
printf("Cannot open Source file.\n");
exit(1);
}
while((ch = (int)fgetc( fp )) != EOF) {
printf("%s",(char*)ch);
send(client, (char*)ch, 1,0);
}
fclose(fp);
//send(client, ret, len,0);
}
Can anybody tell me why is it causing Segmentation Fault??