Link to home
Start Free TrialLog in
Avatar of searchsanjaysharma
searchsanjaysharma

asked on

How to read a string in c dynamically,

void main()
{
         char str[2000];
}
Other way could be
void main()
{
          char *str=(char*)malloc(sizeof(char)*(no.of characters));
}
How can i get the no. of characters in c at runtime.

Is there any way to input a string dynamically without fixing the size.
Avatar of mccarl
mccarl
Flag of Australia image

What do you mean by "input"? Input from where? Someone typing on the console, etc?
Avatar of Kwoof
Kwoof

The norm is for strings to be null-terminated.  If so:

unsigned int x = strlen(str);
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of searchsanjaysharma

ASKER

tx