Monday, July 27, 2009

What is String Assignment in C?

I really need the answer for the question whatt is String Assignment in C. Please help me. Can you also give me a sample program about string assignment? Thanks!! Godbless!!

What is String Assignment in C?
There is no "string" in C. There is in C++





People refer to character arrays as strings. So, if that's what you're referring to, then a "string" assingment would look something like:





char myString[]="This is a string";


char MyString2[20]="";





strcpy(myString2,"String!");





Of course, there are other ways too.
Reply:C++





string%26amp; assign ( const string%26amp; str );


string%26amp; assign ( const string%26amp;, size_t pos, size_t n );


string%26amp; assign ( const char* s, size_t n );


string%26amp; assign ( const char* s );


string%26amp; assign ( size_t n, char c );


template %26lt;class InputIterator%26gt;


string%26amp; assign ( InputIterator first, InputIterator last );





Assign content to string





Assigns new content to the string replacing its current content.





The arguments passed to the function determine the new content:








string%26amp; assign ( const string%26amp; str );


Sets a copy of str as the new content.


string%26amp; assign ( const string%26amp; str, size_t pos, size_t n );


Sets a copy of a substring of str as the new content. The substring is the portion of str that begins at the character position pos and takes up to n characters (it takes less than n if the end of str is reached before).


string%26amp; assign ( const char * s, size_t n );


Sets as the new content a copy of the string formed by the first n characters of the array pointed by s.


string%26amp; assign ( const char * s );


Sets a copy of the string formed by the null-terminated character sequence (C string) pointed by s as the new content. The length of the caracter sequence is determined by the first ocurrence of a null character (as determined by traits.length(s)).


string%26amp; assign ( size_t n, char c );


Sets a string formed by a repetition of character c, n times, as the new content.


template%26lt;class InputIterator%26gt; string%26amp; assign (InputIterator first, InputIterator last);


If InputIterator is an integral type, behaves as the previous member function version, effectively setting as the new content a string formed by the repetition first times of the character equivalent to last.


In any other case, the content is set to the values of the elements that go from element referred to by iterator first to the element right before the one referred to by iterator last
Reply:I'm not giving you a sample program because of the chance that this is a school assignment that you are going to bomb. I don't like chating.


But String Assignment is pretty much when you ASSIGN a value to a STRING. The value has to be inside quotation marks.


No comments:

Post a Comment