100+ errors

This is a discussion on 100+ errors within the C++ Programming forums, part of the General Programming Boards category; I am kind of new to C++ but know some. I am using Dev C++ and am getting all sorts ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    2

    Question 100+ errors

    I am kind of new to C++ but know some. I am using Dev C++ and am getting all sorts of errors from this code.

    Can someone please tell me what I am doing wrong.

    Code:
    #include <cstdlib>
    #include < winsock.h >
    
    WORD version = MAKEWORD(1,1);
    WSADATA wsaData;
    SOCKET theSocket;
    char Buf[256],myBuf[256]; // Buf -for server answer and myBuf -for your commands
    int nRet; // For eventual errors
    
    int conect(char *server) { //Connects to a server using "Winsock"
    
    // Start up Winsock
    nRet=WSAStartup(version, &wsaData);
    if (nRet!=0) {return(0);}
    
    // Store information about the server
    LPHOSTENT lpHostEntry;
    
    lpHostEntry = gethostbyname(server);
    if (lpHostEntry == NULL) {
    WSACleanup();
    return(0);
    }
    
    // Create the socket
    theSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    if (theSocket == INVALID_SOCKET) {
    WSACleanup();
    return(0);
    }
    
    SOCKADDR_IN saServer;
    saServer.sin_family = AF_INET;
    saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
    saServer.sin_port = htons(25); // Port 25
    
    // Connect to the server
    nRet = connect(theSocket,(LPSOCKADDR)&saServer,sizeof(struct sockaddr));
    if (nRet == SOCKET_ERROR) {
    WSACleanup();
    return(0);
    }
    
    nRet = recv(theSocket,Buf,sizeof(Buf),0);
    if (nRet == SOCKET_ERROR) {
    WSACleanup();
    return(0);
    }
    
    if (Buf[0]=='4' || Buf[0]=='5') return(0); // Not a '220' Hello
    if (Buf[0]=='2' && Buf[1]=='2' && Buf[2]=='0') {
    sendmail(); // Ok to send mails
    }
    
    //Close the connection
    closesocket(theSocket);
    
    
    // Shutdown Winsock
    WSACleanup();
    }
    
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        char from [100], mailto [100], msg [500];
        cout << "What is your e-mail address?";
        cin >> from;
        cout << endl << "Who do you want to send to?";
        cin >> mailto;
        cout << "Sending From: " << from << endl << "Sending To: " << mailto << endl;
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    void sendmail() { //Sends an e-mail with MIME encoding
    int err=0;
    char ch[1];
    
    
    // "HELO" the server
    strcpy(myBuf, "HELO <");> strcat(myBuf,helo);
    strcat(myBuf,">\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    recv(theSocket,Buf,sizeof(Buf),0);
    
    
    // MAIL FROM...
    if (Buf[0]=='2' && Buf[1]=='5' && Buf[2]=='0') {
    strcpy(myBuf, "MAIL FROM:<");> strcat(myBuf,from);
    strcat(myBuf,">\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    recv(theSocket,Buf,sizeof(Buf),0);
    }
    
    if (Buf[0]=='4' || Buf[0]=='5') err=1;
    if (Buf[0]=='2' && Buf[1]=='5' && Buf[2]=='0' && err==0) {
    
    
    // MAIL TO...
    strcpy(myBuf, "RCPT TO:<");> strcat(myBuf, mailto);
    strcat(myBuf, ">\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    recv(theSocket,Buf,sizeof(Buf),0);
    }
    
    if (Buf[0]=='4' || Buf[0]=='5') err=1;
    if (Buf[0]=='2' && Buf[1]=='5' && err==0) {
    strcpy(myBuf, "DATA\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
     recv(theSocket,Buf,sizeof(Buf),0);
    }
    
    if (Buf[0]=='4' || Buf[0]=='5') err=1;
    
    
    // MIME encoded message
    if (Buf[0]=='3' && Buf[1]=='5' && Buf[2]=='4' && err==0) {
    strcpy(myBuf, "From: <");> strcat(myBuf, email); // Can change "email" to anything
    strcat(myBuf, ">\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "Subject: Hello\x0d\x0a"); // Your subject goes here
    send(theSocket,myBuf,strlen(myBuf),0);
    
    
    // MIME stuff
    strcpy(myBuf, "MIME-Version: 1.0\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "Content-Type: multipart/mixed;\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, " boundary = \"bla\"\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "X-Priority: 3\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "X -MSMail - Priority: Normal\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "X-Mailer: mailer@localhost\x0d\x0a\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "This is a multi-part message in MIME format.\x0d\x0a\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "--bla\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "Content-Type: text/plain; charset:us-ascii\x0d\x0a\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    
    
    // This is the message (change it as you whish)
    strcpy(myBuf, msg << "\x0d\x0a\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "--bla\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "Content-Type: application/x-msdownload;\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    
    
    }
    f.close();
    strcpy(myBuf, "\x0d\x0a--bla--\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    strcpy(myBuf, "\x0d\x0a.\x0d\x0a"); // End transmission ;)
    send(theSocket,myBuf,strlen(myBuf),0);
    recv(theSocket,Buf,sizeof(Buf),0);
    }
    if (Buf[0]=='4' || Buf[0]=='5') err=1;
    
    
    
    // QUIT (bye bye)
    strcpy(myBuf, "QUIT\x0d\x0a");
    send(theSocket,myBuf,strlen(myBuf),0);
    }

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well you said you are getting over 100 errors. Try posting the first few. Generally when you have that many errors you either are making the same mistake over and over or you have an error that cascades into other compile time errors. But thats all a guess since you haven't given us anything to start from

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    #include <cstdlib>
    #include < winsock.h >
    
    WORD version = MAKEWORD(1,1);
    Put code in functions.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    You know, you can press "compile" long before the program is complete. That way you can more easily spot when you start to do something wrong, rather than relying on people on message boards to fix a whole big mess.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    Also check your spelling. I noticed a "conect" command, later used as "connect". I can't really do socket prorgamming myself, but I can still spot a typo in it. I'm assuming that most of your errors would come from small typos like that. C++ is kinda picky....
    This war, like the next war, is a war to end war.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Location
    UK
    Posts
    109
    As far as I can tell you never connect from main.
    Also sendmail needs to be declared before connect otherwise the compiler will give you an error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  3. getting massive compile errors, need help
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 03-20-2003, 03:05 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 12:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21