answersLogoWhite

0

null character exists at the end of the string.It denotes the end of it.

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Why strcat(string'!') not work in C program?

The strcat() function has the following protocol:char* strcat (char* destination, char* source);The function appends the source string to the destination string and returns the destination string.The destination string must be a null-terminated character array of sufficient length to accommodate strlen (source) plus strlen (destination) characters, plus a null-terminator. The existing null-terminator and subsequent characters of destination are overwritten by characters from the source string, up to and including the source string's null-terminator.strcat (string, '!') will not work because '!' is a character literal (ASCII code 33 decimal), not a null-terminated character array. Use "!" instead of '!'.Example:char string[80]; // character arraystrcpy (string, "Hello world");strcat (string, "!");puts (string);


How are string variables stored?

Typically as null-terminated character arrays. However, some languages use the first element of the array to store the length of the string rather than a null-terminator to mark the end of the string.


Use an assembler directive to store the ASCII-character string What time is it in the memory?

To store the ASCII character string "What time is it" in memory using an assembler directive, you can use the .ascii or .asciz directive. For example, in assembly language, you can write: .data timeString: .asciz "What time is it" This directive allocates memory for the string and includes a null terminator, making it suitable for string handling in many programming contexts.


How you work character type data in array c plus plus?

It's not clear from the question what you mean by "work". However character data types (char and wchar_t) are intended to store character codes and they work exactly the same whether as a single variable or as an array of characters. If you want to use the array as a string, however, remember to include a null-terminator at the end of the string.


How do you write a c program for to replace a character of string either fro mbeginning or ending or at specified location?

The standard C library includes two simple utilities to find the first or last occurance of a given character within a given string, strchr() to search from the start and strrchr() for the reverse start from the end. Subject to the chosen search direction, you could use one of these two simple API. Both return a pointer to the location of the matching character within the string, or NULL if no such character is found. Note that this approach assumes a mutable string, a string stored in writeable memory. A string literal is a constant string and not generally mutable (even though some compilers are very casual about this). That is, strchr("the quick brown fox", 'q') will return a pointer to the first 'q', but since the string is a string of constant characters, you shouldn't use the pointer to change the letter found. To search and modify, you'd use string of variable characters, such as one allocated with the malloc() or strdup() standard API, or one created as a char array.

Related Questions

Why strcat(string'!') not work in C program?

The strcat() function has the following protocol:char* strcat (char* destination, char* source);The function appends the source string to the destination string and returns the destination string.The destination string must be a null-terminated character array of sufficient length to accommodate strlen (source) plus strlen (destination) characters, plus a null-terminator. The existing null-terminator and subsequent characters of destination are overwritten by characters from the source string, up to and including the source string's null-terminator.strcat (string, '!') will not work because '!' is a character literal (ASCII code 33 decimal), not a null-terminated character array. Use "!" instead of '!'.Example:char string[80]; // character arraystrcpy (string, "Hello world");strcat (string, "!");puts (string);


How do you use the strtok function?

strtok sequentially truncate string if delimiter is found. If string is not NULL, the function scans string for the first occurrence of any character included in delimiters. If it is found, the function overwrites the delimiter in string by a null-character and returns a pointer to the token, i.e. the part of the scanned string previous to the delimiter. After a first call to strtok, the function may be called with NULL as string parameter, and it will follow by where the last call to strtok found a delimiter. delimiters may vary from a call to another. Parameters. string Null-terminated string to scan. separator Null-terminated string containing the separators. Return Value. A pointer to the last token found in string. NULL is returned when there are no more tokens to be found. Portability. Defined in ANSI-C.


How are string variables stored?

Typically as null-terminated character arrays. However, some languages use the first element of the array to store the length of the string rather than a null-terminator to mark the end of the string.


Use an assembler directive to store the ASCII-character string What time is it in the memory?

To store the ASCII character string "What time is it" in memory using an assembler directive, you can use the .ascii or .asciz directive. For example, in assembly language, you can write: .data timeString: .asciz "What time is it" This directive allocates memory for the string and includes a null terminator, making it suitable for string handling in many programming contexts.


How strings and characters are represented in an array?

An array of characters is an array of character codes (such as ASCII codes). A string is typically a null-terminated array of characters however some languages use the first array element to specify the string's length.


Program to find the size of the string without using string functions?

You can't. If you want to find the length of a String object, you must use at least one of the String methods. Simply iterate over your char* and count the number of characters you find before you reach the null character . int strLength(const char* str) { int length = 0; // take advantage of the fact that all strings MUST end in a null character while( str[length] != '\0' ) { ++length; } return length; }


Why we don't use NULL character in array?

Because it is not a character, it is a pointer. Anyway, the following is perfectly legal: char str [4] = { 'A', 'B', 'C', (char)NULL};


How you work character type data in array c plus plus?

It's not clear from the question what you mean by "work". However character data types (char and wchar_t) are intended to store character codes and they work exactly the same whether as a single variable or as an array of characters. If you want to use the array as a string, however, remember to include a null-terminator at the end of the string.


How do you reverse a given string in c plus plus?

The simplest way is to use the strrev() function.To manually reverse a string, point to the first and last characters, swap their values, then move the pointers one character towards the middle of the string and repeat. If the pointers point to the same character or pass each other, the string is reversed.The following is an example implementation. The function only process the given string when the string has 2 or more characters and a null-terminator is found within the first lencharacters.#include #include using namespace std;void strRev( char * input, size_t len ){// Minimum length is three (2 characters, 1 null-terminator).const int min = 3;if( len < min )return;// Locate the left-most character.char * l = input;// Locate the null-terminator:char * n = l;while( *n && n < l+len )++n;if( *n )return; // null-terminator not found.// Confirm the length (ignoring null-terminator).if( n-l < min-1 )return;// Locate the right-most character (left of null-terminator)char * r = n-1;// Repeat while right pointer is greater than left pointer.while( r>l ){*n = *l; // use the null-terminator to assist the swap.*l++ = *r; // change left value and advance pointer.*r-- = *n; // change right value and retreat pointer.}// Restore the null terminator.*n = 0;}int main(){// Safest method of entering a string:string input = "";printf( "Enter a string: ");getline( cin, input );// Determine length of input + null-terminator.size_t len = input.length() + 1;// Convert string to a null-terminated string.char * p = ( char * ) calloc( len, sizeof( char ));memcpy( p, input.data(), input.length() );// Reverse the string.strRev( p, len );printf( "Reversed: %s\n", p );// Release memory.free( p );return( 0 );}


Is 'b' or b a character literal?

'b' is a character literal. A character literal is a character enveloped in single quotes, just as a String literal is a String enveloped in double quotes (without the use of a constructor.)


How do you write a c program for to replace a character of string either fro mbeginning or ending or at specified location?

The standard C library includes two simple utilities to find the first or last occurance of a given character within a given string, strchr() to search from the start and strrchr() for the reverse start from the end. Subject to the chosen search direction, you could use one of these two simple API. Both return a pointer to the location of the matching character within the string, or NULL if no such character is found. Note that this approach assumes a mutable string, a string stored in writeable memory. A string literal is a constant string and not generally mutable (even though some compilers are very casual about this). That is, strchr("the quick brown fox", 'q') will return a pointer to the first 'q', but since the string is a string of constant characters, you shouldn't use the pointer to change the letter found. To search and modify, you'd use string of variable characters, such as one allocated with the malloc() or strdup() standard API, or one created as a char array.


How do you write a program to delete all the vowels from a sentence assuming the sentence is no more than 80 characters long?

There is no need to assume the length if the sentence is represented by a null-terminated string. The following function will strip out all the vowels in any null-terminated string of any length, returning the number of vowels removed. Note that we don't create a new string, we simply modify the existing one since we know the modified string cannot be any longer than the existing one. If you want to retain the original string, simply make a copy of it before invoking this function. The p variable is a pointer and will initially refer to the first character of str, which is also a pointer. The cnt variable maintains a count of the vowels we removed. We use the str pointer to advance through the string one character at a time. When str is referring to a vowel we simply advance str to the next character leaving p where it is (effectively ignoring the vowels) and increment cnt. When str refers to a non-vowel, we copy the character from str to p and advance both pointers. When str reaches the null-terminator, we place a null-terminator in p and return the value of cnt. If any vowels were found there will be cnt characters beyond the new null-terminator. If the original string was a fixed-length array then you cannot remove these extra characters, but for variable length strings you may wish to reallocate, reducing the size of the allocation by cnt characters. int strip_vowels (char* str) { char * p = str; int cnt = 0; if (str==NULL) return cnt; while (*str != '\0') // test for null-terminator { switch (*str) // test for vowels { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': str++; // str refers to a vowel, so ignore and advance to next character cnt++; // increment the count break; default: *p++ = *str++; // non-vowel -- copy the character and advance both pointers break; } } *p = '\0'; // ensure the modified string is null-terminated! return cnt; }