Tags » C Program

c program, please help me to complete program

**Can you write me a C program that does the following:

  • The program works in a windows cmd window.

  • It runs like this:
    yourprogram file1.txt file2.txt…

  • 132 more words
Recent Questions - Stack Overflow

Why C is NOT a memory safe language.

When you become more experienced in C programming you eventually hit pointers, and the memory problems associated with them. Well, let’s face it, the minute you start dealing with arrays and strings in C there is a chance of something going awry. 416 more words

Programming

DFS algorithm implementing with c program

DFS  or  depth first search algorithm technique is used mainly for graphs . It is recursive algorithm.
Followed in all Btech or BE  colleges and books in India as well as all over the world… 18 more words

C Program, recv() error: Connection reset by peer

I have some Problems using the recv() and send() functions.

here’s my code:

#include "performConnection.h"
#include "errno.h"



//checks if the first arguement of an answer is "+"
bool checkPlus(char buffer[]){
int position = strcspn(buffer,"+");
if (position==0){
    return true;
}
else{
    return false;
}

}

int performConnection(int socketDescriptor){
bool check;
char buffer;
memset(&buffer, 0, sizeof(buffer));
char string;
memset(&string, 0, sizeof(string));
int n;                      //Bytes received/send




//receiving data from server//accepting connections
n = recv(socketDescriptor, buffer, 255,0);
if(n<0){
    perror("recv() failed");
    printf("Exiting program");

    return EXIT_FAILURE;                    //exit program if receive failed
}
else{
    check = checkPlus(buffer);  //+ check for positive answer
    if (check==false){
        perror("failure");
        return EXIT_FAILURE;    //exit program if -
    }

}
printf("%s\n", buffer);
memset(buffer, 0, sizeof(buffer));



//send GAMEVERSION to server
n = send(socketDescriptor,GAMEVERSION, 255, 0);
if(n<0){
    perror("send() failed");
    printf("exiting program");
    return EXIT_FAILURE;                    //exit program if send() fails
}

printf("Gameversion: %i, %s",n, GAMEVERSION);

//receive server data
n = recv(socketDescriptor, buffer, 255, 0);
 if(n<0){
    perror("recv() failed");
    printf("Exiting program");

    return EXIT_FAILURE;                    //exit program if recv() fails
}
else{
    check = checkPlus(buffer);  //+ check for positive answer
    if (check==false){
        perror("failure");
        return EXIT_FAILURE;                //exit program if negative answer
    }
}

printf("%s\n", buffer);
memset(&buffer,0, sizeof(buffer));



    strcpy(buffer,"ID K.GcY_EqHAs\n");
    printf("%s\n",buffer);
    n = send(socketDescriptor, buffer, 255,0);
    if(n<0){
        perror("send() failed");
        printf("Exiting program");

        return EXIT_FAILURE;
    }

   memset(&buffer, 0, sizeof(buffer));


n = recv(socketDescriptor, buffer, 255, 0);

 if(n<0){
    perror("recv() failed");
    printf("Exiting program");
    printf("\n%s\n", buffer);
    return EXIT_FAILURE;                    //exit program if recv() fails
}
else{
    check = checkPlus(buffer);  //+ check for positive answer
    if (check==false){
        perror("failure");

        return EXIT_FAILURE;                //exit program if negative answer
    }
}   
printf("%s",buffer);

return EXIT_SUCCESS;

}
… 115 more words
Recent Questions - Stack Overflow