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??

Ancient Dragon commented: Stop cross-posting! -7

>>printf("%s",(char*)ch);

I've told you about that before in another thread. %s says the next argument is a character array, but all you are passing is a single character. What you should use is "%c", then remove that damned typecast.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.