Thread: reading txt file from the internet website

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    64

    reading txt file from the internet website

    hello,
    i want read a txt file on the internet i.e (http://dhagames.my3gb.com/dhagc.txt)

    i actually want that i am making a game zone which has subscription from internet and the below program opens the website for subscription and user enters his username and password he want to set for this gaming zone.and his username and password saves in above txt file and i want to read this txt file through c program.how to do that?please help.a piece of code will be good help.i dont want u to do this for me but please help.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <conio.h>
    int main()
    {
        char* pass;
        char* p="hello";
        int i=0,x;
        printf("You have to register First in order to use our Game zone");
        printf("\nPress 1 to open our website\n");
        scanf("%d",&x);
        if (x==1)
        {
            system("start firefox.exe www.dhagames.my3gb.com/dha.html");
        }
        printf("Enter password and press ENTER.\n \n");
    
        {
            printf("Password: ");
            scanf( "%s",  pass);
    
            if(strcmp ( pass, p ) == 0)
            {
                printf("Correct Password. \n \n");
                i=10;
            }
            else
            {
                if(strcmp ( pass, "hint" ) == 0)
                {
                    printf("Password Hint: Form of salutation. \n \n");
                }
                else
                {
                    printf("Incorrect Password. \nType 'hint' for help. \n \n");
                    i++;
                }
            }
    
        }
    
    
    
    
    
    }

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    The way you have it now, your program will only work if the user uses Firefox on Windows. Also, get rid of the magic number 10 on line 26. Change:

    Code:
    scanf("%d",&x);
    if (x == 1) { /* ... */
    to
    Code:
    if (getchar() == 1) { /* ... */
    If you really want to interface with a website, learn how to use sockets and make POST/GET requests to send and receive data on HTTP clients. These links should help you:

    HTTP/1.1: Method Definitions (http protocol)

    Beej's Guide to Network Programming (sockets)

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Do it all in Javascript perhaps?

    I mean, you have all the connection infrastructure of your browser to hand, and it will likely simplify the whole process. And once you're over the initial learning hump, you'll have a new skill to play with.

    You can "browse" the web with a C API such as libcurl, but you'll find yourself doing a lot of things just to get you in place to solve the problem. It might be OK if all you want to do is "fetch" and "post" something, but if you're also looking to control your browser (more than just starting it), it could get really messy in a hurry.
    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.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    64
    i just want to copy it in a string aur txt file in my computer.dont want to control any thing.can you tell me how to include this libcurl in my codeblocks mingw compiler.??

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Quote Originally Posted by danishzaidi View Post
    i just want to copy it in a string aur txt file in my computer.dont want to control any thing.can you tell me how to include this libcurl in my codeblocks mingw compiler.??
    how to add libcurl library?

    We've been over this. ^^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using data from an internet website
    By danieldelatorre in forum C Programming
    Replies: 3
    Last Post: 10-17-2011, 05:59 PM
  2. Reading from a website?
    By Paul22000 in forum C++ Programming
    Replies: 15
    Last Post: 11-12-2008, 08:12 PM
  3. Reading text files on the internet
    By Mavix in forum C# Programming
    Replies: 8
    Last Post: 06-20-2007, 05:38 AM
  4. Reading HTML files and Images from Website
    By Fade_to_Blah in forum C Programming
    Replies: 5
    Last Post: 07-08-2005, 08:49 AM
  5. Reading Files off the internet
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 03-24-2002, 02:18 PM