ok im trying to work on map system that reads from a text file.
and from each bit i can assign to a variable
example data
/////////////////////
3|32|45|
23|32|23|
55|4|55|
12|3|77|
etc....
......
/////////////////////
so for example i read the first line and i want to break the string up into smaller part so Var[1] = 3, Var[2] = 32 and so on until it get the last part then reads a new line.
for the coding bit this is what i could come up with:
char* GetStringPart(string InStr,char Breaker,int Num)
{
//variables
string StrTemp(InStr);
int StrLength = StrTemp.length();
int LastCharBreaker = 0;
int CurrentCharBreaker = 0;
char Buffer[32];
size_t length;
//For loop it
for(int A=0;A<=StrLength;A++)
{
if (StrTemp.at(A)==Breaker)
{LastCharBreaker=CurrentCharBreaker;CurrentCharBreaker=A;}
}
//get string part;
length = StrTemp.copy(Buffer,LastCharBreaker+1,CurrentCharBreaker-1);
Buffer[length]='\0';
return Buffer;
}
But i when i try it with a test with this code:
#include <Windows.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int CanLoop = 1;
char* GetStringPart(string Str,char Break,int Num);
int main()
{
//////////
// begining
string MainString = "2|65|32|23|";
char* StringChar;
int StrPos[10];
for(int a=0;a<=10;a++)
{StrPos[a]=-1;}
//decode the string
StringChar = GetStringPart(MainString,"|",1);
cout << StringChar << endl ;
StringChar = GetStringPart(MainString,"|",2);
cout << StringChar << endl ;
StringChar = GetStringPart(MainString,"|",3);
cout << StringChar << endl ;
//pause
system("pause");
//return to windows
return -1;
}
i get these errors:
1>------ Build started: Project: MapSystemDebug, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\administratormatt\documents\visual studio 2010\projects\mapsystemdebug\mapsystemdebug\main.cpp(19): error C2664: 'GetStringPart' : cannot convert parameter 2 from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>c:\users\administratormatt\documents\visual studio 2010\projects\mapsystemdebug\mapsystemdebug\main.cpp(21): error C2664: 'GetStringPart' : cannot convert parameter 2 from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>c:\users\administratormatt\documents\visual studio 2010\projects\mapsystemdebug\mapsystemdebug\main.cpp(23): error C2664: 'GetStringPart' : cannot convert parameter 2 from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>c:\users\administratormatt\documents\visual studio 2010\projects\mapsystemdebug\mapsystemdebug\main.cpp(49): warning C4172: returning address of local variable or temporary
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
can you point out to me how i can fix these errors and improve my code?
Problem Solution That Never Fails: "Build A Bridge And Get Over It"