|
|
|
#11 (permalink) | |||||||||
|
PC Gamer
|
Quote:
That is why I'm trying to make my own functions you see. It is a bit of practise and they will make my life a lot easier in my future programs. Xaimus, thanks. Is that meant to chop off characters from the beginning and end because I can't get it to work hmmm I'm not very good am I?Anyone know what i'm doing wrong in my functions yet and how to fix them? Well... I know it is to do with the pointers.... i think... but I really don't know what to do with it to make it work. I'm tring to use the same arguments as the functions in Liberty Basic ![]()
__________________
Kris
|
|||||||||
|
|
|
|
|
#12 (permalink) | ||||||||||||
|
<3 TB303
![]() |
Quote:
It's supposed to shift around the characters inside the string and then seal off the appropriate area with a NULL to remove certain areas of the string, but I can not test it here. bleh, work
|
||||||||||||
|
|
|
|
#13 (permalink) | ||
|
Overclocker
|
Quote:
Quote:
- You haven't allocated any memory for newSentence to point to, use malloc and free to allocate and deallocate the memory. Also, you may want to consider other options for returning the value, as currently your calling code will have to free the returned memory on its own or it will lead to a memory leak. - You shouldn't be using the += operator to copy the character to the new string, instead simply use the = operator. Otherwise you're relying on the compiler to initialize the memory pointed to by newSentence to 0, not terribly robust. - Don't redeclare newSentence inside the for loop, it's already been declared outside the loop. Hopefully this will get you on the road to success.
__________________
DD TDX waterblock DD Maze 4-1 CPU (w. Peltier) Swiftech pump DD reservoir DD radiator Dual heatercore |
||
|
|
|
|
#14 (permalink) | ||||||||
|
PC Gamer
|
Code:
char* Mid(char *Sentence, int FromNumber, int ToNumber)
{
char* newSentence = (char *) malloc(1000);
if (ToNumber == 0)
ToNumber = KrisIO::Len(Sentence);
for (int i = (FromNumber--); i <= ToNumber; i++)
{
*(newSentence+(i-FromNumber)) = *(Sentence+i);
}
return newSentence;
}
══════════ before and after the string. It is also not very efficient and probably uses up lots of memory. Where would I free the memory? Any help on clearing the string of ══════════ ? Thanks, I'm going to work now but keep posting!! Still got the Upper() function to do after this lol. ![]()
__________________
Kris
|
||||||||
|
|
|
|
|
#15 (permalink) | |||||
|
Programmer
|
Free the variable before the return.
__________________on upper casing a whole array of characters it'd be nothing more than... Code:
char i[80],b[80]; for(int n=0; i!='NULL'; n++) b[n]=toupper(i[n]); Code:
string blue, you; you = toupper(blue);
|
|||||
|
|
|
|
#16 (permalink) | |||||||||||
|
PC Gamer
|
Quote:
Umm.. the first one says: Quote:
And the second one says says: Quote:
Will freeing the memory get rid of all of the ========='s in my Mid() function? Sorry, I'm probably getting annoying now
__________________
Kris
|
|||||||||||
|
|
|
|
|
#17 (permalink) | ||||||
|
Programmer
|
Quote:
|
||||||
|
|
|
|
#18 (permalink) | |||||||||
|
PC Gamer
|
Quote:
If i assign "hello" to the variable i, the result is: HELLO╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠ ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠hello ![]()
__________________
Kris
|
|||||||||
|
|
|
|
|
#19 (permalink) | |
|
Overclocker
|
Quote:
Second, the string of ='s or other symbols is probably put there by your compiler in debug mode. You're not putting a null terminator on the end of the new string you create. Before you return the new string try putting something along the lines of: *( newSentence + ( toNumber - fromNumber ) ) = 0;
__________________
DD TDX waterblock DD Maze 4-1 CPU (w. Peltier) Swiftech pump DD reservoir DD radiator Dual heatercore |
|
|
|
|
|
#20 (permalink) | ||||||||||
|
PC Gamer
|
Quote:
PHP Code:
Plus, thanks to this code from you: Quote:
It's all going well Thank you
__________________
Kris
|
||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|