Can't you include string.h ? Use stdlib.h sizeof() and then search for '\0' (string end symb). You can make it even simplier by memsetting your string to some char (for example '\n') and then testing for that..
Ilya
P.S.: (You can later convert all the free mem to '\0' so that your print keeps clean)
P.P.S.: If all else fails instead of char symb. use hexidecimals (the true form of special chars)
Here's my code. I just want to return the length of a string. How do I do that? Any assistance would be greatly appreciated.
#include "stdafx.h"
#using
using namespace System;
int _tmain()
{
String *strString;
int intLength;
Console::Write(S"Enter a String ");
strString = Console::ReadLine();
Console::Write(strString);
intLength = strlen(strString);
Console::Write(intLength);
return 0;
}
I run this and get a slew of "Cannot convert..." errors.
Valmian
Junior Poster in Training
82 posts since Sep 2003
Reputation Points: 13
Solved Threads: 0
Although I must say your problem is strange...
Valmian
Junior Poster in Training
82 posts since Sep 2003
Reputation Points: 13
Solved Threads: 0
ok..
here is something i didn't test:
int strings(char *string)
{
int size=0;
for (;string[size]!='\0'; size++)
continue;
return size;
}
Valmian
Junior Poster in Training
82 posts since Sep 2003
Reputation Points: 13
Solved Threads: 0
ok.. I tested it and to my suprise (my stuf ususally doesn't work from the first try) it actually worked.. so I hope you won't have problems with it.
Ilyaa :)
Valmian
Junior Poster in Training
82 posts since Sep 2003
Reputation Points: 13
Solved Threads: 0
Valmian
Junior Poster in Training
82 posts since Sep 2003
Reputation Points: 13
Solved Threads: 0
Your problem might be that strlen returns size_t or smthn so and you are using int.. although I always thought that size_t was made by "typedef size_t int;"
Ilya
Here's my code. I just want to return the length of a string. How do I do that? Any assistance would be greatly appreciated.
#include "stdafx.h"
#using
using namespace System;
int _tmain()
{
String *strString;
int intLength;
Console::Write(S"Enter a String ");
strString = Console::ReadLine();
Console::Write(strString);
intLength = strlen(strString);
Console::Write(intLength);
return 0;
}
I run this and get a slew of "Cannot convert..." errors.
Valmian
Junior Poster in Training
82 posts since Sep 2003
Reputation Points: 13
Solved Threads: 0