Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Get() And Put() In C++

c++ strings ascii value

  • Please log in to reply
2 replies to this topic

#1 Hydrokr0n1k

Hydrokr0n1k

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts
  • Learning:C++, JavaScript

Posted 22 April 2012 - 11:22 PM

hello my favorite community :)
so I am having an issue


why is it not pulling up the text from online source?

I have tried using get/put to use a copy of the text on my computer and the internet but I am still getting an error but untill I figure out where exactly the rest of these functions go sequentially I am a little stuck lol

#include <iostream>
#include <cmath>
using namespace std;

[color=#FFA500]--------------------------------------------------------[/color]
[color=#ffa500]This is the part I am having trouble with as well[/color]
[color=#ffa500]what would I use to call the functions below[/color]
asciistring([color=#FF0000]what goes here????[/color]);
doubledelete([color=#FF0000]what goes here????[/color]);
numberwordsinstring([color=#FF0000]what goes here????[/color]);
int getput([color=#ff0000]does anything actually go here?[/color]);
[color=#ffa500]--------------------------------------------------------[/color]

    int getput()
    {
    string [color=#ff0000]what goes here????[/color];
    fstream streamObject("http://www.gutenberg.org/cache/epub/1342/pg1342.txt");
    fstream localFile("pap.txt");
    fstream newFile("new.txt");
    
    
    
        if(streamObject.fail())
            cout << "file failed to load." << endl;
        else
            cout << "file load was successful." << endl;
    
        if(localFile.fail())
            cout << "file2 failed to load." << endl;
        else
            cout << "file load was successful." << endl;
    
        while(!streamObject.eof())
        {
            streamObject.put(localFile.get());
        }
    
        streamObject.close();
    
        char single = localFile.get();
        while(!localFile.eof())
        {
            [color=#ff0000]what goes here????[/color] += single;
            single = localFile.get();
    
        }
        localFile << newFile;
    
        localFile.close();
    
        asciistring([color=#ff0000]what goes here????[/color]);
        doubledelete([color=#ff0000]what goes here????[/color]);
        numberwordsinstring([color=#ff0000]what goes here????[/color]);
    
    
    
    
    
        return 0;
    
    }
**************************************************************************************************
        int asciistring() { 
    
    char String[100]; 
    int Sum,Index; 
    Sum=0; //Sum is initially zero 
    
    printf("Enter the string:\n"); 
    gets(String); //Accept String from User 
    
    for(Index=0;Index<strlen(String);Index++) 
    { 
    Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. 
    } 
    
    printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. 
    
    return 0; 
    
    }
**************************************************************************************************
 
     int doubledelete()
{
    
        cout << forceSingleSpaces1("sentence1.  sentence2.  end.  ") << endl;
    
        return EXIT_SUCCESS;
}
**************************************************************************************************

    int numberwordsinstring()
    {
        int i, numspaces;
        char nextChar;
        string msg;
    
        numspaces=1;
    
        cout << "Type in a string\n";
        getline(cin, msg);
    
        // checks each character in the string
        for (i=0; i<int(msg.length()); i++)
        {
            nextChar = msg.at(i); // gets a character
            if (isspace(msg[i]))
                numspaces++;
        }
        cout << "\nThere are " << numspaces << " words in this string.";
        cin.ignore();
        return 0;
    }

  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 23 April 2012 - 03:55 AM

What I understand from your post is that you want to download a file from a website and you want to save it on your computer. Am I right? In that case, you need to use a socket to connect to the site and download the content. Then you need to save it on your machine. So first read/study about socket programming. Irrespective of OS, you can use the MinGW socket API to do that. If you want to do OS specific way, there are samples for that too.

Windows example: http://www.codeproje...C-for-the-Begin
Linux example: http://www.linuxhowt..._C /socket.htm
  • 0

#3 Hydrokr0n1k

Hydrokr0n1k

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts
  • Learning:C++, JavaScript

Posted 23 April 2012 - 11:06 AM

I tried reading the article quite a bit of information there can I not just have the program call/get it from an online source? or is that the purpose of the "winsock"?
  • 0





Also tagged with one or more of these keywords: c++, strings, ascii value

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download