answersLogoWhite

0


Best Answer

char *ptr;

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you declare a pointer to a character string in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is return type of string in c?

In C programming, a string doesn't have a specific return type as it's essentially an array of characters. So, if a function is returning a string, it should be declared to return a pointer to a char (char*), since a string in C is represented as an array of characters terminated by a null character ('\0').


What is the difference between null pointer ASCII null character and null string?

A null pointer is a pointer which does not point to any valid memory location, and usually contains the binary value "0" to represent this (this is language dependent). The ASCII null character is a character-sized zero value (in ASCII, it is an unsigned byte with a value of 0), and typically represents the end of a string (esp. as in C and C++). A null string is one that is zero characters of usable string data; in a length-based string, this means the length parameter is set to 0, and in an ASCII null-terminated string, means the first character is set to 0.


Replace a character by another character in a given string?

C SolutionTo replace a single, specified character with another in a given string, one possibility is ...char *pszString; /* pointer to string */int offset; /* offset of desired character */... initialize pszString and offset*(pszString+offset) = 'A'; /* or whatever new value you want */Obviously, this is a simple example, and it does not consider if offset is greater than the size of the array.If you want to replace every occurence of a character with another, here is another possibility, one that also handles string length ...char *pszString; /* pointer to string */char* pszTemp; /* temporary scanning pointer */char cOldChar; /* character to change */char cNewChar; /* new character */... initialize pszString, cOldChar, and cNewCharfor (pszTemp = pszString; *pszTemp != '\0'; pszTemp++) { /* scan */if (*pszTemp == cOldChar) *pszTemp = cNewChar; /* conditionally replace */}Java Solution// Replace all 'e' characters with 'i' characters in String strstr.replaceAll("e", "i");


What is cputs function in computer c plus plus?

Nothing.The C language only recognizes a few keywords, like "for" and "if". Most of what's in a C program ... that doesn't reference routines in the C program itself ... are library calls, and cputs() is one of those. What it does is write its argument (which should be a pointer to a character string) to the console... console put 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

What is return type of string in c?

In C programming, a string doesn't have a specific return type as it's essentially an array of characters. So, if a function is returning a string, it should be declared to return a pointer to a char (char*), since a string in C is represented as an array of characters terminated by a null character ('\0').


How do you declare pointer in c?

ujkjkyjljlui kukhjkui


What is the difference between null pointer ASCII null character and null string?

A null pointer is a pointer which does not point to any valid memory location, and usually contains the binary value "0" to represent this (this is language dependent). The ASCII null character is a character-sized zero value (in ASCII, it is an unsigned byte with a value of 0), and typically represents the end of a string (esp. as in C and C++). A null string is one that is zero characters of usable string data; in a length-based string, this means the length parameter is set to 0, and in an ASCII null-terminated string, means the first character is set to 0.


How do you declare a pointer variable in c?

int* pint; // instantiate a pointer to an int. float* pflt; // instantiate a pointer to a float.


In C programming what is pointer?

Simply put, a pointer is a memory address. It "points" to data at that address. The Data Type of the pointer tells the program how to interpret the data at the address. For example, a character pointer will read the data at the address as a byte and interpret it as a character (like an ASCII character, for instance). A string pointer is just like a character pointer, except that it starts reading characters at the address and keeps going until it encounters a null (a data value of zero). The "string" of characters is interpreted as text. The available data types include just about anything you can imagine. Intrinsic types, structures, functions... in later versions of C, pointers can point to objects.


How do you declare a string array and add elements to it in C plus plus?

You cannot add elements to a fixed array in C or C++. If, however, the array is declared as a pointer to an array, you can add elements by allocating a new array, copying/adding elements as needed, reassigning the new array to the pointer, and deallocating the original array.


Replace a character by another character in a given string?

C SolutionTo replace a single, specified character with another in a given string, one possibility is ...char *pszString; /* pointer to string */int offset; /* offset of desired character */... initialize pszString and offset*(pszString+offset) = 'A'; /* or whatever new value you want */Obviously, this is a simple example, and it does not consider if offset is greater than the size of the array.If you want to replace every occurence of a character with another, here is another possibility, one that also handles string length ...char *pszString; /* pointer to string */char* pszTemp; /* temporary scanning pointer */char cOldChar; /* character to change */char cNewChar; /* new character */... initialize pszString, cOldChar, and cNewCharfor (pszTemp = pszString; *pszTemp != '\0'; pszTemp++) { /* scan */if (*pszTemp == cOldChar) *pszTemp = cNewChar; /* conditionally replace */}Java Solution// Replace all 'e' characters with 'i' characters in String strstr.replaceAll("e", "i");


What is cputs function in computer c plus plus?

Nothing.The C language only recognizes a few keywords, like "for" and "if". Most of what's in a C program ... that doesn't reference routines in the C program itself ... are library calls, and cputs() is one of those. What it does is write its argument (which should be a pointer to a character string) to the console... console put 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.


What procedure or operator allows you to extract a single character from a string in c plus plus?

Use the array index operator. Strings are just arrays of characters so use the zero-based index of the character you are interested in. Alternatively, use pointer arithmetic to achieve the same thing. Note that the string's name is a reference to the start of the character array.


How do you write a function that counts the number of characters in a string?

As this is probably a homework question, I will give you some pseudo code: [code] num_chars = 0 READ ch FROM string WHILE ch IS NOT END OF STRING num_chars = num_chars + 1 READ ch FROM string END WHILE [/code] Remember that in C, we use what are called "C-strings". C-strings are a pointer to a continuous group of characters in memory which are terminated by a null character. The null character is '\0', and has an integer value of 0. The C-string generally points to the first character in the string. To access the value of this character, you must use the dereferencing operator, *. If you want to move to the next character, you simply add 1 to the pointer. So if you have a C-string: char *str = "abcd"; then: *str '\0' Anything past the null character is undefined. Trying to access this data is considered to be a buffer overflow, and is very dangerous. Note that c-strings created as pointers should always be treated as immutable, as trying to change them might produce errors. Many compilers will allocate the above string inside the static data area, along with any constants or literals which can not fit inside the immediate field of an instruction. If you want a mutable string, then declare it as a character array: char str[] = "abcd"; This method of declaration will explicitly allocate memory on the stack to store the c string in, and as such, the string can be safely manipulated without fear of unintended side effects.


A number or a string of c character is called as?

Constant.