Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C (http://www.programmingforums.org/forum60.html)
-   -   web page - internet connection [Error] :( (http://www.programmingforums.org/showthread.php?t=11296)

boraciner Sep 12th, 2006 2:42 AM

web page - internet connection [Error] :(
 
I found these codes somewhere.. It takes a website adress and makes "index.html" after copied these source codes from the adress..but I can't compile it..
please help me..

:

#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>



int main(void)
{
FILE *html;

int syc=0;

char        buf[]="GET\n\n";
unsigned char gelenveri[1000];
char adres[50];
char myadres[50];

WSADATA        wsdata;
SOCKET s;

struct hostent *he;
struct sockaddr_in their_addr;

//#############################################################################
  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
  WORD wOldColorAttrs;
  CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  GetConsoleScreenBufferInfo(h, &csbiInfo);
  wOldColorAttrs = csbiInfo.wAttributes;

  SetConsoleTextAttribute ( h, FOREGROUND_GREEN |FOREGROUND_INTENSITY| 50);
  printf ("--------------------------------------------------------------------\n" );
  SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY | 50); //FOREGROUND_INTENSITY );
  printf ("--------------------------- bycodec loader -------------------------\n" );
  //SetConsoleTextAttribute ( h, wOldColorAttrs);
  SetConsoleTextAttribute ( h,  FOREGROUND_GREEN | FOREGROUND_INTENSITY | 50);
  printf ("------------------------- by-codec@hotmail.com ---------------------\n\n\n" );
  SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
//#############################################################################

WSAStartup(MAKEWORD(2,0),&wsdata);



printf(" hostname  : ");
SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_INTENSITY );
scanf("%s",myadres);
html = fopen("index.html","w");
if((he = gethostbyname(myadres))== NULL){
        printf("gethostbyname error !!!");
  system("pause");
  exit(-1);
  }

their_addr.sin_family        = AF_INET;
their_addr.sin_port    = htons(80);
their_addr.sin_addr        = *((struct in_addr *)he->h_addr);
memset(&(their_addr.sin_zero),'\0',8);

s=socket(AF_INET,SOCK_STREAM,0);
if(s<0){
        printf("soket hatasi");
  system("pause");
  exit(-1);
  }

if((connect(s,(struct sockaddr *)&their_addr,sizeof(struct sockaddr))) == -1){
        printf("baglanti hatasi\n\n");
  system("pause");
  exit(-1);
  }                  //

if((send(s,buf,strlen(buf),0))== -1){
        printf("veri gönderme hatasi");
  system("pause");
  exit(-1);
  }
SetConsoleTextAttribute ( h, FOREGROUND_BLUE | FOREGROUND_INTENSITY );
printf("\n\n\n\n");
printf("###########################################################################\n\n");

for(;;){
if((recv(s,gelenveri,1000,0)) == 0){
  fclose(html);
  WSACleanup();
  printf("\n\n\n\n\n");
  SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
  printf("program basarIyLa sonlandI\nindex.html yaratILdI...\CIkmak icin bi tusa basIn ");
  SetConsoleTextAttribute ( h, FOREGROUND_BLUE | FOREGROUND_INTENSITY );
  printf("\n\n\n\n");
  printf("###########################################################################\n\n");

  getch();
  exit(-1);
  }
//-------------------------- </HTML>

//--------------------------
fputs(gelenveri,html);
SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_INTENSITY | 45 );
printf("%s",gelenveri);
memset(gelenveri,'\0',1000);
}





return 0;
}



DevCpp

:

Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp" -o "C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"  -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp: In function `int main()':
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:86: error: invalid conversion from `unsigned char*' to `char*'

C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:86: error:  initializing argument 2 of `int recv(SOCKET, char*, int, int)'
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:91:11: warning: unknown escape sequence '\C'
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:102: error: invalid conversion from `unsigned char*' to `const char*'
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:102: error:  initializing argument 1 of `int fputs(const char*, FILE*)'

Execution terminated


Borland Shows more than that...


:(

The Dark Sep 12th, 2006 4:15 AM

Those errors seem pretty straightforward.
Delete the red bit in this code:
:

unsigned char gelenveri[1000];

Fix up the \C to a proper escape sequence in this code (did you mean \nC ?):
:

  printf("program basarIyLa sonlandI\nindex.html yaratILdI...\CIkmak icin bi tusa basIn ");

boraciner Sep 12th, 2006 9:48 AM

I fixed these errors but it didn't work again...
:

Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp" -o "C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"  -L"C:\Dev-Cpp\lib"
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x124):bycodecserver.cpp: undefined reference to `WSAStartup@8'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x187):bycodecserver.cpp: undefined reference to `gethostbyname@4'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x1d2):bycodecserver.cpp: undefined reference to `htons@4'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x22c):bycodecserver.cpp: undefined reference to `socket@12'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x255):bycodecserver.cpp: undefined reference to `connect@12'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x2ad):bycodecserver.cpp: undefined reference to `send@16'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x332):bycodecserver.cpp: undefined reference to `recv@16'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x34d):bycodecserver.cpp: undefined reference to `WSACleanup@0'
collect2: ld returned 1 exit status

Execution terminated



will it work ???

The Dark Sep 12th, 2006 8:57 PM

You need to link with the library that has those functions in it. In this case you need to link with wsock32.lib

boraciner Sep 13th, 2006 1:49 AM

ok .. I'm trying to find this library..

thank you again.
If I have a question ,I'll write there ...

thanks a lot


All times are GMT -5. The time now is 1:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC