Click here to Skip to main content
15,861,172 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralSOLVED : Accessing struct member and getting error I do not know how to fix it. Pin
Vaclav_21-Aug-15 5:57
Vaclav_21-Aug-15 5:57 
QuestionUsing #define wrong way ? Pin
Vaclav_20-Aug-15 6:56
Vaclav_20-Aug-15 6:56 
AnswerRe: Using #define wrong way ? Pin
k505420-Aug-15 7:10
mvek505420-Aug-15 7:10 
GeneralSOLVED Re: Using #define wrong way ? Pin
Vaclav_20-Aug-15 8:07
Vaclav_20-Aug-15 8:07 
QuestionRe: Using #define wrong way ? Pin
CPallini20-Aug-15 21:06
mveCPallini20-Aug-15 21:06 
AnswerRe: Using #define wrong way ? Pin
Vaclav_21-Aug-15 4:12
Vaclav_21-Aug-15 4:12 
GeneralRe: Using #define wrong way ? Pin
Stefan_Lang31-Aug-15 22:02
Stefan_Lang31-Aug-15 22:02 
QuestionHow to send a text file from C to java and receive the same text file from java to C Pin
venkat28vk18-Aug-15 20:57
venkat28vk18-Aug-15 20:57 
I would like to know how to send a text file from C to java, in which java has to receive the file and send it back to C. I have developed the code, but i am facing error in the receive function
#include<time.h>
#include<errno.h>
#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>

#include<stdlib.h>
#include<sys stat.h="">
#include<sys time.h="">
#include<sys ioctl.h="">
#include<sys types.h="">
#include<arpa inet.h="">
#include<sys select.h="">
#include<sys socket.h="">

int send_text(int socket)

{
FILE *text;
char a[50];
int size, read_size, stat, packet_index;
char send_buffer[8008], read_buffer[8008];
int wrt=0,sock_fd,tsize=0;
packet_index = 1;
int i=0;
text = fopen("/home/sosdt009/Desktop/character3.txt", "r");
if (text == NULL)
{
printf("Error Opening text File:");
exit(-1);
}

printf("Getting text Size:\n");
gets(a);
fseek(text, 0, SEEK_END);
size = ftell(text);
fseek(text, 0, SEEK_SET);
printf("Total text size: %d \n", size);
gets(a);
//Send text Size

printf("Sending text Size:\n",size);
gets(a);
send(socket, (void *)&size, sizeof(size), 0);

/*do

{<br />
    stat = recv(socket, read_buffer, 1024, 0);

}*/while(stat < 0)
printf("Socket data:%s \n", read_buffer); 
gets(a);<br />
while(size>tsize) 
{

    //Read from the file into our send buffer
    read_size = fread(send_buffer,1,sizeof(send_buffer),text);
    printf("The size of send buffer:%c \n",send_buffer);
    gets(a);
    printf("The read size value is :%d \n", read_size);
    gets(a);

    //Send data through our socket 

    do
    {<br />
        stat = send(socket, send_buffer, read_size, 0);
        printf("The send size value is: %d \n", size);
        gets(a);
        printf("The read size value is: %d \n", read_size);
        gets(a);

    } while (stat < 0); 
    printf("Packet %d, sent %d bytes.\n", packet_index, read_size);
    gets(a);

    //packet_index++;
    //Zero out our send buffer

    tsize = tsize+read_size;
    printf("The tsize value is:%d \n",tsize);
    gets(a);
        memset(send_buffer,0, sizeof(send_buffer));

    if(read_size<=NULL)
    {
        printf("The connection is transferred to received text: \n");
        gets(a);
    }
}
fclose(text);
//close(socket);
printf("Text successfully send:\n");
gets(a);
return 0;   

}

int receive_text(int socket)
{
int buffersize = 77,recv_size=0,read_size = 1, write_size,size;
char *pBuf,a[50],b[77];
int errnom,i;
FILE *textnew;
size_t rec;
textnew = fopen("/home/sosdt009/Desktop/receivednew.txt", "a");

if (textnew == NULL)

{

printf("Error has occurred, text file could not be opened \n");
return -1;
}
//Loop while we have not received the entire file yet

 while(read_size > 0)
{

        //ioctl(socket, FIONREAD, &buffersize);
        printf("The Buffersize is    :%d\n",buffersize);
        gets(a);
        printf("The size of socket is:%d\n",socket);
        gets(a);

    //We check to see if there is data to be read from the socket 

    if (buffersize > 0)
    {
        printf("Buffersize value is  :%d\n", buffersize);
        gets(a);
        pBuf = malloc(sizeof(b));
        if (!pBuf)
        {
            printf(errnom, "Memory Error Cannot Allocate!\n");
            gets(a);
            exit(-1);
        }

        //read_size = read(socket,pBuf,buffersize);
        //read_size = fread(pBuf,buffersize,1,textnew);

        read_size = recv(socket,pBuf,sizeof(pBuf),1);
        //memset(pBuf,'\0',sizeof(pBuf));
        printf("Read size value is :%d \n",read_size);
        gets(a);
        printf("Buffersize value is:%d \n",sizeof(pBuf));
        gets(a);

        /*if (read_size < 0)
        {
            printf("%d\n",strerror(errno));
            printf("Data not written to the file:\n");
            gets(a);
            goto free;
        }*/

        //Write the currently read data into our text file

        //write_size = write(textnew,read_size,pBuf);                //using write function
        write_size = fwrite(pBuf,1,sizeof(pBuf),textnew); 
        free(pBuf);
        printf("Write size value is   :%d \n",write_size);
        gets(a);
        printf("Buffer size value is  :%d \n",sizeof(pBuf));
        gets(a);            

        //Increment the total number of bytes read

        recv_size += read_size;
        printf("Received size value is:%d \n",recv_size);
        gets(a);
        printf("Read size value is    :%d \n",read_size);       
        gets(a);    
    }
}
free:
fclose(textnew);
close(socket);  
printf("Text Successfully Received:\n");
gets(a);
return 0;

}

int main(int argc,char *argv[])
{
int socket_desc;
struct sockaddr_in server;
char *parray,errnomu;
//Create socket

socket_desc = socket(AF_INET,SOCK_STREAM,0);
if(socket_desc == -1)
{
      printf("Could not create socket \n");
}
      memset(&server,0,sizeof(server));
      server.sin_addr.s_addr = inet_addr("10.170.0.38");
      server.sin_family = AF_INET;
      server.sin_port = htons(6999);

//Connect to remote server

      if (connect(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
      {

         printf(strerror(errnomu));<br />
         printf("Connect Error \n");
             return -1;<br />
          }

     puts("Connected");
     send_text(socket_desc);
     receive_text(socket_desc);
     close(socket_desc);
     return 0;

}
AnswerRe: How to send a text file from C to java and receive the same text file from java to C Pin
Richard MacCutchan18-Aug-15 21:53
mveRichard MacCutchan18-Aug-15 21:53 
QuestionRe: How to send a text file from C to java and receive the same text file from java to C Pin
David Crow19-Aug-15 5:24
David Crow19-Aug-15 5:24 
AnswerRe: How to send a text file from C to java and receive the same text file from java to C Pin
ThatsAlok20-Aug-15 0:23
ThatsAlok20-Aug-15 0:23 
GeneralOT Pin
CPallini20-Aug-15 0:35
mveCPallini20-Aug-15 0:35 
GeneralRe: OT Pin
ThatsAlok20-Aug-15 1:51
ThatsAlok20-Aug-15 1:51 
GeneralRe: OT Pin
ThatsAlok20-Aug-15 1:53
ThatsAlok20-Aug-15 1:53 
QuestionCMFCToolBarComboBoxButton::GetByCmd returns NULL Pin
joliet17-Aug-15 20:26
joliet17-Aug-15 20:26 
AnswerRe: CMFCToolBarComboBoxButton::GetByCmd returns NULL Pin
Jochen Arndt17-Aug-15 20:59
professionalJochen Arndt17-Aug-15 20:59 
QuestionAdjust paper size Pin
Erich Ruth17-Aug-15 10:02
Erich Ruth17-Aug-15 10:02 
AnswerRe: Adjust paper size Pin
Kenneth Walters17-Aug-15 11:09
Kenneth Walters17-Aug-15 11:09 
QuestionWindows 10 & WM_QUERY_ENDSESSION/WM_ENDSESSION Pin
Peter Weyzen17-Aug-15 4:51
Peter Weyzen17-Aug-15 4:51 
Questionc++ Qt or C# or JAVA !! Pin
Dreamer_X15-Aug-15 3:51
Dreamer_X15-Aug-15 3:51 
AnswerRe: c++ Qt or C# or JAVA !! Pin
OriginalGriff15-Aug-15 3:54
mveOriginalGriff15-Aug-15 3:54 
AnswerRe: c++ Qt or C# or JAVA !! Pin
ThatsAlok20-Aug-15 0:24
ThatsAlok20-Aug-15 0:24 
QuestionFirst button of toolbar control get activated after another button get executed Pin
Amrit Agr14-Aug-15 1:35
Amrit Agr14-Aug-15 1:35 
QuestionCheckbox: SetFocus() doesn't draw broken rectangle around it Pin
Donguy197613-Aug-15 13:39
Donguy197613-Aug-15 13:39 
AnswerRe: Checkbox: SetFocus() doesn't draw broken rectangle around it Pin
Arthur V. Ratz13-Aug-15 19:13
professionalArthur V. Ratz13-Aug-15 19:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.