Thread: Replace Function

  1. #1
    Registered User DrFox's Avatar
    Join Date
    Jun 2005
    Posts
    4

    Replace Function

    Hello, I'm new to C++ programming, but I have 4 years of Visual Basic programming, and I know a couple of languages. I was wondering if there was a function already made that resembles the VB function, Replace. I have done google searching for 2 hours now and I can't seem to find one.

    The VB command looks like this:
    Replace((string)String, (string)WhatToReplace, (string)ReplaceWithThis)

    I am using an array of characters, not an actual string by the way.

    I also tried to write my own function to do this and failed three times.

    Any help would be appreciated.

    Thanks,

    Fox

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Code:
    #include<string>
    
    int main()
    {
    
         string yo;
         string mamma;
    
         yo = mamma;
    
    return 0;
    }
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Quote Originally Posted by The Brain
    (code)
    You should give him code that compiles.
    Code:
    #include<string>
    
    int main()
    {
         using namespace std;
         string yo;
         string mamma;
    
         yo = mamma;
    
    return 0;
    }
    Away.

  4. #4
    Registered User DrFox's Avatar
    Join Date
    Jun 2005
    Posts
    4
    Thats not quite what I had in mind. :P

    I would be looking for a function that can do this:

    In the string: "WAdddDWFS" could replace all the d's with a certain character, but the D's aren't always in the same spot.

    Here is my project so far, I got all the pragma stuff from my friend Dave, who knows more C++ then I do, the rest is by me.

    Code:
    #pragma comment(lib, "msvcrt.lib")
    #pragma comment(linker, "/NODEFAULTLIB:LIBCD")
    #pragma comment(linker,"/SECTION:.text,EWR /IGNORE:4078")
    #pragma comment(linker,"/OPT:NOWIN98")
    #pragma comment(linker,"/MERGE:.rdata=.text /MERGE:.data=.text")
    
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    /*
      F6 = 117
      F7 = 118
      F11 = 122
    */
    
    HWND	winHandle;
    DWORD	prcID;
    long	memLocation;
    HANDLE	prcHandle;
    long	i;
    char	strTemp[255];
    
    void main()
    {
    	printf("-------------------------\n| Blazes StarCraft Hack |\n-------------------------\n");
    
    	GetWindowThreadProcessId(FindWindow(NULL, "Brood War"), &prcID);
    	if (prcID == 0)
    	{
    		printf("Error     : Could not find BroodWar Process.\nSuggestion: Start BroodWar\n\n");
    		system("pause");
    		exit(0);
    	}
    	prcHandle = OpenProcess(0x1F0FFF, false, prcID);
    	printf("Loaded Successfully\n");
    	while(1)
    	{
    		if (GetAsyncKeyState(117) != 0)
    		{
    			for(i = 0x1000094; i <= 0xFF00094; i += 0x10000)
    			{	
    				ReadProcessMemory(prcHandle, (LPVOID)i, &strTemp, 5, NULL);
    				if (strcmp(strTemp, "start") == 0)
    				{
    					memLocation = i;
    					printf("Found TextBox Address\n");
    				}
    			}
    		}
    
    		if (GetAsyncKeyState(118) != 0 && memLocation != 0)
    		{
    			ReadProcessMemory(prcHandle, (LPVOID)memLocation, &strTemp, 254, NULL);
    			
                            //Need Replace Function here!
    
    			WriteProcessMemory(prcHandle, (LPVOID)memLocation, &strTemp, strlen(strTemp), NULL);
    			printf("Wrote color message sucessfully");
    		}
    
    		if (GetAsyncKeyState(122) != 0)
    		{
    			break;
    		}
    
    		Sleep(100);
    	}
    	printf("\nThank you for using the program. :)\n");
    	system("pause");
    }
    Last edited by DrFox; 06-25-2005 at 04:47 PM.

  5. #5
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    #include<algorithm>

    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  6. #6
    Registered User DrFox's Avatar
    Join Date
    Jun 2005
    Posts
    4
    Thank you. :-)

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    All this is wrong:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    This is wrong:
    Code:
    void main()
    {
    I don't know what this is:
    Code:
    #pragma comment(lib, "msvcrt.lib")
    #pragma comment(linker, "/NODEFAULTLIB:LIBCD")
    #pragma comment(linker,"/SECTION:.text,EWR /IGNORE:4078")
    #pragma comment(linker,"/OPT:NOWIN98")
    #pragma comment(linker,"/MERGE:.rdata=.text /MERGE:.data=.text")
    but my guess is you should delete it from your program.

    And, this isn't C++:
    Code:
    printf( )
    Last edited by 7stud; 06-25-2005 at 10:00 PM.

  8. #8
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    code fine, wrong board only stud

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM