hi all
new programmer learning C here, the book I've read is basically restricted to text based output and the language itself. While I practice I was wanting to create a few text based games to make it fun as the exercises in the book are very boring. However to create a "cool" atmosphere I am wanting to simulate typing when I print text rather than it appear straight away. I have figured out how to do this, but I am struggling on how to pass or find the actual string length to my new print function. Here is the doubtless silly attempt I've come up with so far :
#include <stdio.h>
#include <windows.h>
void print(char * text);
int main(void)
{
print("This is some text");
return 0;
}
void print(char * text)
{
int length;
for(length = 0; length < 5000; ++length)
{
text += 1;
if (*text == '\0')
break;
}
for(int i = 0; i < length; ++i)
{
printf("%c", text[i]);
Sleep(10);
}
}
I am just trying to understand how I determine the length of the passed string in a clean manner, rather than telling it to search upto 5000 characters looking for the NULL termination, which doesn't work anyway.
Thanks for any help!