[c]Using arrays – 2

1. Physical size array, assign the actual size of the array.
2. Logical size array, the actual size you use.

Here’s the sample code:

#include <stdio.h>

int main()
{
    char text[100]; //physical size of array.
    int i=0;
    
    printf("Enter any text:");
    scanf("%s",text); //For string format specifier no need to use &, accept one word only.
    
    /*Uncomment below to accept multiple words until user press enter.*/
    //scanf("%[^\n]s",text); 
    
    while(text[i]!='\0') //\0 is the terminating character.
    {
        i++;
    }
    printf("Logical size is %d\n",i);
    return 0;
}
Advertisements
This entry was posted in General stuffs. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s